8/11/2013

846 - Steps - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         int x , y;
  6.         int testCases;
  7.         int min_steps = 0;
  8.         cin>>testCases;
  9.        
  10.         for(int i=0; i<testCases ; i++)
  11.         {
  12.                 cin>>x>>y;
  13.                 int difference = y - x;
  14.                 min_steps = 0;
  15.                 if(difference != 0)
  16.                 {
  17.                          int sumOfSteps = 0;
  18.                       int z = 2; //divided by 2, it represents the size if the next step
  19.                         while(difference > sumOfSteps)
  20.                         {
  21.                                 sumOfSteps += (/ 2); //next step
  22.                                 min_steps++;
  23.                                 z++;
  24.                         }
  25.                 }
  26.                
  27.                 cout<<min_steps<<endl;
  28.         }
  29.         return 0;
  30. }


    You can find more of my solutions on
     Here

8/01/2013

10079 - Pizza Cutting - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         long long N , Max;
  6.         while(true)
  7.         {
  8.                 cin>>N;
  9.                 if(N<0)break;
  10.                 else{
  11.                         Max = N*(N+1)/2+1;
  12.                         cout<<Max<<endl;
  13.                 }
  14.         }
  15.         return 0;
  16. }


    You can find more of my solutions on Here

11764 - Jumping Mario - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         int arr[50];
  6.         int testCases ;
  7.         int N;
  8.        
  9.         cin>>testCases;
  10.         for(int i=0; i<testCases ; i++){
  11.                 cin>>N;
  12.                 int ups = 0 , downs = 0; //counters
  13.                 for(int ii=1; ii<=N; ii++){
  14.                         cin>>arr[ii];
  15.                 }
  16.                 for(int j=1; j<N; j++){
  17.                         if(arr[j]<arr[j+1])
  18.                                 ++ups;
  19.                     if(arr[j]>arr[j+1])
  20.                                 ++downs;
  21.                         if(arr[j] == arr[j+1])
  22.                                 continue;
  23.                         }
  24.        
  25.                
  26.                 cout<<"Case "<<i+1<<": "<<ups<<" "<<downs<<endl;
  27.         }
  28.         return 0;
  29. }


    You can find more of my solutions on
     Here

7/31/2013

11636 - Hello World! - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         int pastes  , N , lines;
  6.         int i = 0;
  7.         while(cin>>N)
  8.         {
  9.                 i++;
  10.                 lines = 1;
  11.                 pastes = 0;
  12.                 if(N<0)
  13.                         break;
  14.                 else if(== 1)
  15.                 {
  16.                         pastes = 0;
  17.                 }
  18.                 else
  19.                 {
  20.                         while(true)
  21.                         {
  22.                                 lines *=2;
  23.                                 if(lines >= N)
  24.                                 {
  25.                                         pastes++;
  26.                                         break;
  27.                                 }
  28.                                 else
  29.                                         pastes++;
  30.                         }
  31.                 }
  32.                 cout<<"Case "<<i<<": "<<pastes<<endl;
  33.         }
  34.         return 0;
  35. }


    You can find more of my solutions on Here

7/26/2013

11805 - Bafana Bafana - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         int testCases , N , K , P , position;
  6.        
  7.         cin>>testCases;
  8.        
  9.         for(int i = 0 ; i<testCases ; i++)
  10.         {
  11.                 cin>>N>>K>>P;
  12.                 position = K + P;
  13.                 while(position  > N)
  14.                 {
  15.                         position-=N;
  16.                 }
  17.                 cout<<"Case "<<i+1<<": "<<position<<endl;
  18.         }
  19.         return 0;
  20. }


    You can find more of my solutions on
     Here

7/25/2013

488 - Triangle Wave - UVA

  1. #include<iostream>
  2. using namespace std;
  3. void printWave(int amplitude)
  4. {
  5.         for(int i = 1; i <= amplitude; i++){
  6.                 for(int ii = 1; ii <= i; ii++){
  7.                         cout<<i;
  8.                 }
  9.                 cout<<endl;
  10.         }
  11.         for(int j = amplitude-1; j >= 1; j--){
  12.                 for(int jj = 1; jj<=; jj++){
  13.                         cout<<j;
  14.                 }
  15.                 cout<<endl;
  16.         }
  17. }
  18. int main ()
  19. {
  20.         int cases , amp , freq;
  21.         cin>>cases;
  22.         for(int i=0 ; i<cases ; i++){
  23.                 if(i>0) cout<<endl;
  24.                 cin>>amp>>freq;
  25.                 for(int j=0 ; j<freq; j++){
  26.                         if(j>0)cout<<endl;
  27.                         printWave(amp);
  28.                 }
  29.         }
  30.         return 0;
  31. }


    You can find more of my solutions on
     Here

7/11/2013

the 3n+1 Problem - 100 - UVA

  1. #include <iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int main ()
  5. {
  6.         int n , i , j;
  7.         while(cin>>i>>j)
  8.         {
  9.                 int tempi = i;
  10.                 int tempj = j;
  11.                 if(i>j)
  12.                         swap(i,j);
  13.                
  14.                 int maxCycle_Length = INT_MIN;
  15.                 int cycle_Length;
  16.                 while(i<=j)
  17.                 {
  18.                         n=i;
  19.                         cycle_Length = 1;
  20.                         while(n!=1){
  21.                                 if(n%2!=0)
  22.                                         n=(3*n)+1;
  23.                                 else
  24.                                         n = n/2;
  25.                                 cycle_Length++;
  26.                         }
  27.                         if(cycle_Length > maxCycle_Length)
  28.                                 maxCycle_Length = cycle_Length;
  29.                         i++;
  30.                 }
  31.                 cout<<tempi<<" "<<tempj<<" "<<maxCycle_Length<<endl;
  32.         }
  33.        
  34.         return 0;
  35. }


    You can find more of my solutions on
     Here