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 dushen12 at 2011-05-07 22:33:59 on Problem 2014
In Reply To:Re:水题不断WA 谁帮忙看下···· Posted by:dushen12 at 2011-05-07 22:22:19
else
> 			{
> 				if(td>y) y+=td;
> 				tl=0;
> 				td=0;
> 				tl=l;
> 				td=d;
> 			}
 //未判断tl,因为tl可变 y 也要更新
修改后你的源码:
248k 0ms
#include<iostream>
 using namespace std;
 int main()
{
 	int maxl,l,d,tl,td,x,y;
	while(cin>>maxl)
 	{
 		if(maxl==0) break;
 		tl=0;
 		td=0;
 		x=0;
 		y=0;
 		while(cin>>l>>d)
 		{
 			if(l==-1 && d==-1) break;
 			if(tl+l<=maxl)
 			{
 				tl+=l;
 				if(d>td) td=d;
 				if(tl>x) x=tl; 
 			}
 			else
 			{
				if(tl>x ) x=tl;
 				 y+=td;
 				
 				tl=l;
 				td=d;
 			}
 		}
 		if(tl>x) x=tl;
 		y+=td;
 		cout<<x<<" x "<<y<<endl;
 	}
 	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