Pages

Sunday, September 20, 2009

UVA Problem#10055

Question:

Solution:
int main(){
...
... 
if(a>b) 
d=(a-b); 
else d=(b-a);  
...
...

Saturday, September 19, 2009

UVA Problem#10812

Question:
http://uva.onlinejudge.org/external/108/10812.html 

Solution:
1. run the loop down to n
2. take the input s and d.
3. Print the output using this technique:        
if(s<d || (s+d)%2 || (s-d)%2)
            printf("impossible\n");
        else{
            a=(s+d)/2;
            b=(s-a);
            if(a>b)
                printf("%d %d\n", a, b);
            else
                printf("%d %d\n", b, a);
        }
 

Thursday, September 17, 2009

UVA Problem#11185

Question:

Solution Techniques:
 1. take input.
2. use the following formula to get the ternary of the number

ternary[i] = decimal%3; 
decimal = decimal/3; 
i++;

3. Show the output. 

UVA Problem#10071

#include <stdio.h>

int main(){
int v, t;
while(scanf("%d%d", &v, &t)==2)
printf("%d\n", 2*v*t);
return 0;
}

Wednesday, September 16, 2009

UVA Problem#11172

Question:
http://uva.onlinejudge.org/external/111/11172.html 

Solution Method:
it is one of the most easiest problem of UVA. 
1. take simple input 
2. bye simple comparing you can achieve the proper output.


UVA Problem#11636

Question:
http://uva.onlinejudge.org/external/116/11636.html 

Solution: 
int main(){ 
...
..... 
scanf("%d", &n); 
if(n<0) break; 
if(n>1){
j = 0; 
line = 1; 
for(j=1; ; j++){
line *= 2; 
if(line >= n) break; 
}
  ....
....} 

UVA Problem#10783

Question:

Solution Method:
 1. loop will run from the given starting value till the gien end value
2. check for the odd numbers
3. simply add them 

UVA Problem#575

Question:
http://uva.onlinejudge.org/external/5/575.html 

Solution:
int main(){
.....
.... 
for(i=0; i<l; i++){
            s=1;
            for(j=l; j>i; j--){
                s*=2;
            }
   
            k+=((a[i]-48)*(s-1));
        }

......
..... 


UVA Problem#438

Question:

Solution:
int main(){
.....
.... 
m1= (y2-y1)/(x2-x1); 
m2= (y3-y1)/(x3-x1); 
if (m2==0){
  k= (x2-x3)/m1/2 + (y1+y2)/2; 
h= (x1+x3)/2; }
if (m1==0){
  k=(x3-x2)/m2/2 + (y1+y3)/2; 
h=(x1+x2)/2; 
}
else if (m1!=0&&m2!=0){ 
h= ((x1+x2)/m1 - (x1+x3)/m2 + y2-y3)/2/(1/m1 - 1/m2);
  k= ( h-(x1+x2)/2)/(-m1) + (y1+y2)/2; 
}
r= sqrt((h-x1)*(h-x1) + (k-y1)*(k-y1)); 
ans=2*pi*r;   
......
...

UVA Problem#369

Question:

Solution: 
double fact(int n){ 
int i; double f=1; 
for(i=2; i<=n; i++){ 
f = f*i; 
return f; 
}
int main(){ 
....
.... 
c = fact(n) / ( fact(n-m) * fact(m) ) 
... 
}



UVA Problem#113

Question: 

Solution:
y=exp((1/n)*log(p)); 

Friday, September 11, 2009

Addison-Wesley_Concrete.Mathematics

An essential book for solving the program related to mathematics! Very usefull though very difficult!!
click here to download

Wednesday, September 9, 2009

Introduction to Algorithm-Cormen

A book of algorithm by Cormen. Algorithms are must to do well in any kind of programming contest.
 
click here to download

Art of Programming Contest

A wonderful book for the amateur contestant. This book is a must to know all the ABC of a programming contest.