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

用int   循环条件 min <= max

Posted by nuciedh at 2007-07-23 12:07:26 on Problem 3273
In Reply To:我也是用二分法做的 ,怎么就不对了? Posted by:19106118 at 2007-07-23 11:32:15
> 我不知道是我判断的方法不对,,还是其他什么问题,哪位帮忙指点一下啊,代码写的很简单的
> 
> 
> #include <stdio.h>
> int main()
> {
>     long m,n,i,k;
>     double a[100000],min,max,mid,sum;
>     while(EOF!=scanf("%d%d",&m,&n))
>     {
>         min=1;max=0;
>         for(i=0;i<m;i++)
>         {
>             scanf("%lf",a+i);
>             if(min<a[i])min=a[i];
>             max+=a[i];
>         }
>         while(max-min>0.1)
>         {
>             mid=(max+min)/2;
>             k=0;
>             sum=0;
>             for(i=0;i<m;i++)
>             {
>                 sum+=a[i];
>                 if(sum>mid)
>                 {
>                     sum=a[i];
>                     k++;
>                 }
>                 else if(sum==mid)
>                 {
>                     sum=0;
>                     k++;
>                 }
>             }
>             if(k<=n)max=mid;
>             else min=mid;
>         
>         }
>         printf("%.0lf\n",mid);
>     }        
> }

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