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

Re:晕那里错了吗,帮我看一下,高手们

Posted by A1B1 at 2007-08-07 15:01:07 on Problem 3017
In Reply To:晕那里错了吗,帮我看一下,高手们 Posted by:redbox at 2006-10-02 02:45:30
算法有问题,
8 17
2 2 2 8 1 4 2 1这组数据答案就不对
> #include <stdio.h>
>  
> int main(void)
> {
>     int buffer[100000];
>     _int64 n,m,sum,temp;
>     int i,t;	
>     scanf("%I64d %I64d",&n,&m);
>     for(i=0;i<n;i++)
>     {
>         scanf("%d",&buffer[i]);
>     }
>     sum=0;
>     t=buffer[0];
>     temp=0;
>     for(i=0;i<n;i++)
>     {
> 
>         if(temp+buffer[i]<=m && buffer[i]<=t)
>         {		
>             temp+=buffer[i];
>     	}
>         else
>     	{
>             if(buffer[i]>m) {
>             	sum=-1;
>             	break;
>     		}
>             temp=t=buffer[i];
>             sum+=t;
>             t=buffer[i];
> 			
> 
>     	}
>     }
> 	sum+=t;
>     printf("%I64d\n",sum);
>     getchar();
>     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