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 20112430138 at 2013-05-15 15:38:59 on Problem 3273
#include<stdio.h>
#include<stdlib.h>
int a[10000];
int m,n;
int main()
{
    int i,mid;
    int max=0;
    int min=0;
    int judge(int mid,int a[]);
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)
    scanf("%d",&a[i]);
    for(i=1;i<=n;i++)
       max=max+a[i];
    for(i=1;i<=n;i++)
        if(min<a[i])
        min=a[i];
    mid=(min+max)/2;
    while(min<max)
{
    mid=(min+max)/2;
    if((judge(mid,a))==1)
           min=min+1;
    else
           max=max-1;              
    }
    printf("%d",mid);
    system("pause");
    return 0;
} 


   
int judge(int mid,int a[])
{
    int i,sum=0;
    int group=1;
    for(i=1;i<=n;i++)
     {
         if(sum<=mid)
         sum=sum+a[i];
         else
            {
               sum=a[i];
               group++;       }
                              }
       if(group>m)
             return 1;
       else
             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