Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么暴力求解WA了,感觉思路没错。。跪求大神指教

Posted by AK47biubiubiu at 2016-04-17 10:15:01 on Problem 2590
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
    int t,a,b;
    long long x,sum;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&a,&b);
        if(abs(a-b)<=3)
            printf("%d\n",abs(a-b));
        else
        {
            a+=1;
            sum=x=2;
            while(a!=b-1)
            {
                if(a+x<=b-1)
                {
                    sum++;
                    a+=x;
                    x++;
                }
                else
                    x--;
            }
            printf("%I64d\n",sum);
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator