首页 > 其他 > 详细

uva 846 - Steps

时间:2014-07-22 23:17:05      阅读:505      评论:0      收藏:0      [点我收藏+]

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

bubuko.com,布布扣
#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;
        
    }
}
bubuko.com,布布扣

uva 846 - Steps

原文:http://www.cnblogs.com/royjwy/p/3514089.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!