- #include<iostream>
- using namespace std;
- int main ()
- {
- int x , y;
- int testCases;
- int min_steps = 0;
- cin>>testCases;
- for(int i=0; i<testCases ; i++)
- {
- cin>>x>>y;
- int difference = y - x;
- min_steps = 0;
- if(difference != 0)
- {
- int sumOfSteps = 0;
- int z = 2; //divided by 2, it represents the size if the next step
- while(difference > sumOfSteps)
- {
- sumOfSteps += (z / 2); //next step
- min_steps++;
- z++;
- }
- }
- cout<<min_steps<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
8/11/2013
846 - Steps - UVA
8/01/2013
10079 - Pizza Cutting - UVA
- #include<iostream>
- using namespace std;
- int main ()
- {
- long long N , Max;
- while(true)
- {
- cin>>N;
- if(N<0)break;
- else{
- Max = N*(N+1)/2+1;
- cout<<Max<<endl;
- }
- }
- return 0;
- }
You can find more of my solutions on Here
11764 - Jumping Mario - UVA
- #include<iostream>
- using namespace std;
- int main ()
- {
- int arr[50];
- int testCases ;
- int N;
- cin>>testCases;
- for(int i=0; i<testCases ; i++){
- cin>>N;
- int ups = 0 , downs = 0; //counters
- for(int ii=1; ii<=N; ii++){
- cin>>arr[ii];
- }
- for(int j=1; j<N; j++){
- if(arr[j]<arr[j+1])
- ++ups;
- if(arr[j]>arr[j+1])
- ++downs;
- if(arr[j] == arr[j+1])
- continue;
- }
- cout<<"Case "<<i+1<<": "<<ups<<" "<<downs<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
7/31/2013
11636 - Hello World! - UVA
- #include<iostream>
- using namespace std;
- int main ()
- {
- int pastes , N , lines;
- int i = 0;
- while(cin>>N)
- {
- i++;
- lines = 1;
- pastes = 0;
- if(N<0)
- break;
- else if(N == 1)
- {
- pastes = 0;
- }
- else
- {
- while(true)
- {
- lines *=2;
- if(lines >= N)
- {
- pastes++;
- break;
- }
- else
- pastes++;
- }
- }
- cout<<"Case "<<i<<": "<<pastes<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
7/26/2013
11805 - Bafana Bafana - UVA
- #include<iostream>
- using namespace std;
- int main ()
- {
- int testCases , N , K , P , position;
- cin>>testCases;
- for(int i = 0 ; i<testCases ; i++)
- {
- cin>>N>>K>>P;
- position = K + P;
- while(position > N)
- {
- position-=N;
- }
- cout<<"Case "<<i+1<<": "<<position<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
7/25/2013
488 - Triangle Wave - UVA
- #include<iostream>
- using namespace std;
- void printWave(int amplitude)
- {
- for(int i = 1; i <= amplitude; i++){
- for(int ii = 1; ii <= i; ii++){
- cout<<i;
- }
- cout<<endl;
- }
- for(int j = amplitude-1; j >= 1; j--){
- for(int jj = 1; jj<=j ; jj++){
- cout<<j;
- }
- cout<<endl;
- }
- }
- int main ()
- {
- int cases , amp , freq;
- cin>>cases;
- for(int i=0 ; i<cases ; i++){
- if(i>0) cout<<endl;
- cin>>amp>>freq;
- for(int j=0 ; j<freq; j++){
- if(j>0)cout<<endl;
- printWave(amp);
- }
- }
- return 0;
- }
You can find more of my solutions on Here
7/11/2013
the 3n+1 Problem - 100 - UVA
- #include <iostream>
- #include<algorithm>
- using namespace std;
- int main ()
- {
- int n , i , j;
- while(cin>>i>>j)
- {
- int tempi = i;
- int tempj = j;
- if(i>j)
- swap(i,j);
- int maxCycle_Length = INT_MIN;
- int cycle_Length;
- while(i<=j)
- {
- n=i;
- cycle_Length = 1;
- while(n!=1){
- if(n%2!=0)
- n=(3*n)+1;
- else
- n = n/2;
- cycle_Length++;
- }
- if(cycle_Length > maxCycle_Length)
- maxCycle_Length = cycle_Length;
- i++;
- }
- cout<<tempi<<" "<<tempj<<" "<<maxCycle_Length<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
Subscribe to:
Comments (Atom)