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