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:有同学帮我看看哪儿不对吗?example都通过了,就是wrong answerIn Reply To:有同学帮我看看哪儿不对吗?example都通过了,就是wrong answer Posted by:scy at 2005-09-13 21:58:53 > /*先按min从大到小排序,尽可能的先装满min,再把remain依次分配给各个瓶子,直到装满, > 如果所有的都装满,还有剩余的就输出remain,但是如果还有没装满的就表示没有剩余了*/ > > #include<iostream> > using namespace std; > > typedef struct node{ > float min; > float max; > int n; > }NODE; > NODE sizes1[101]; > > > int main() > { > long amount; > int num; > float minimal,maximal; > char c; > while(cin>>c) > { > cin.putback(c); > cin>>amount>>num; > if(amout==0){cout<<0<<end;continue;} > for(int i=1;i<=num;i++) > {cin>>minimal>>maximal;sizes1[i].min=minimal/1000;sizes1[i].max=maximal/1000;sizes1[i].n=0;} > > //按min的大小从大到小排列 > for(i=1;i<num;i++) > { > minimal=sizes1[i].min; > int j=i; > for(int k=i+1;k<=num;k++) > { > if(sizes1[k].min>minimal){minimal=sizes1[k].min;j=k;} > } > NODE t; > t=sizes1[i]; > sizes1[i]=sizes1[j];sizes1[j]=t; > } > float remain=0,contain=0; > for(i=1;i<=num;i++) > { > while(1) > { > contain+=sizes1[i].min; > remain=amount-contain; > sizes1[i].n++; > if(remain>=sizes1[i].min)continue; > else > { > if(remain<0){contain-=sizes1[i].min;remain+=sizes1[i].min;sizes1[i].n--;} > break; > } > } > } > for(i=1;i<=num;i++) > { > while(sizes1[i].n>0) > { > remain=remain-(sizes1[i].max-sizes1[i].min); > if(remain>0)sizes1[i].n--; > else break; > } > if(remain<=0){remain=0;break;} > } > remain=remain*1000; > cout<<remain<<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