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 yanhaofeng at 2007-07-22 09:48:22 on Problem 3273
In Reply To:见内 Posted by:nwpu_ghost at 2007-07-21 18:51:50
#include<stdio.h>
int m,n,a[1000010];
int check(int mid)
{    int nu=0,month=1,i,k;
      for(i=1;i<=n;i++)
      { k=nu+a[i];
        if(k>mid)
        { month++;nu=a[i];  }
        else{ nu+=a[i]; }
        if(month>m)return -1;
         
      }
      return month;
}
int main()
{ int i,j,k,min,max,mid;
  int nu,month;
  while(1)
  { scanf("%d%d",&n,&m);
    min=-1;
    for(i=1;i<=n;i++)
    { scanf("%d",&a[i]);
      if(min<a[i])min=a[i];
    }
    max=10000;mid=0;
    while(min<max-1)
    { mid=(min+max)/2;
      month=check(mid);
      if(month==-1){min=mid;continue;}
      if(month<=m)max=mid;
      
    }
    month=check(min);k=check(max);
    j=check(mid);
    if(month==m)mid=min;
    if(j==-1)mid=max;
    printf("%d\n",mid);break;
  }  
}

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