| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:你的代码错在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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator