uva 846 - Steps

wa了两次才纠正,虽然想法对了,还是要自己先多测几组数据

#include<iostream>
#include<math.h>
using namespace std;
int main(){
    int x,y;
    int n;
    cin>>n;
    while(n--){
        cin>>x>>y;
        if(x==y){
            cout<<"0"<<endl;
            continue;
        }
        int n = (int)sqrt((double)(y-x));
        if(n==1)
            cout<<y-x<<endl;
        else
            cout<<2*n-1+(y-x-n*n)/n+(((y-x-n*n)%n)?1:0)<<endl;
        
    }
}

 

posted on 2014-01-10 17:20  云在心  阅读(150)  评论(0)    收藏  举报

导航