POJ2590 Steps

来源:互联网 发布:富二代体验知乎 编辑:程序博客网 时间:2024/05/22 15:25

题目链接:http://poj.org/problem?id=2590

题思路:

水题,找规律。

AC代码:

#include<iostream>#include<cstdio>#include<cmath>using namespace std;int main(){    int T;    scanf("%d",&T);    while(T--)    {        int x,y,step;        scanf("%d%d",&x,&y);        int t=y-x;        int a=sqrt(t*1.0);        int b=a*(a+1);        if(b>t)        {            if(a*(a-1)+a<t)                step=2*a;            else                step=2*a-1;        }        else if(t-b==0)            step=2*a;        else if(t-b>a)            step=2*a+2;        else            step=2*a+1;        printf("%d\n",step);    }    return 0;}


0 0
原创粉丝点击