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

大于和等于应该分开吧?

Posted by sunmc at 2005-08-18 09:36:48 on Problem 2590
In Reply To:请教牛人们觉得没错,为什么会WA呢???????????????????? Posted by:jiabiao at 2005-08-17 23:22:36
> #include<stdio.h>
> void main()
> {
>   long x,y,i,n,m,sum,data,count;
>   scanf("%ld",&n);
>   for(i=0;i<n;i++)
>   {
>      scanf("%ld %ld",&x,&y);
>      x++;y--;
>      m=y-x;
>      data=2;sum=x;count=2;
>      while(sum<y)
>      {
>        if(sum+data>=y) //大于和等于应该分开吧?
>        {
>          printf("%ld\n",++count);
>          break;
>        }
>        if(sum+data<y)
>        {
>          sum=sum+data;
>          data++;count++;
>        }
>      }
>   }
> }
> 

不会overflow的,最好用公式算,效率会高很多。

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