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 |
那组BT数据真够BT我花了10秒中#include<iostream> using namespace std; struct BKStick { int length; int preid; }; struct MKStick { int length; int lastid; }; int q(BKStick a[],int low,int high) { BKStick key=a[low]; while(low<high) { while(low<high && a[high].length>=key.length)high--; a[low]=a[high]; while(low<high && a[low].length<=key.length)low++; a[high]=a[low]; } a[low]=key; return low; } void qs(BKStick a[],int low,int high) { if(low<high) { int m=q(a,low,high); qs(a,low,m-1); qs(a,m+1,high); } } int main() { // freopen("1.txt","r",stdin); BKStick bkstick[64]; MKStick mkstick[3200]; int MKlength,ALLlength,BKsum,MKsum,MKSsum; int i; while(1) { MKSsum=0; ALLlength=0; cin>>BKsum; if(!BKsum)break; for(i=0;i<BKsum;i++) { cin>>bkstick[i].length; bkstick[i].preid=-2; ALLlength+=bkstick[i].length; } qs(bkstick,0,BKsum-1); MKlength=bkstick[BKsum-1].length-1; MKsum=BKsum; while(MKSsum!=MKsum) { MKlength++; while(ALLlength%MKlength) { MKlength++; } MKSsum=0; MKsum=ALLlength/MKlength; for(i=0;i<MKsum;i++) { mkstick[i].length=0; mkstick[i].lastid=-1; } i=-1; while(!(MKSsum==-1 || MKSsum==MKsum)) { i++; while(bkstick[i].preid!=-2 && i<BKsum)i++; if(i>=BKsum)//退回一步要考虑已经为空的情况 { i=mkstick[MKSsum].lastid; mkstick[MKSsum].length-=bkstick[i].length; mkstick[MKSsum].lastid=bkstick[i].preid; bkstick[i].preid=-2; if(mkstick[MKSsum].lastid==-1) { MKSsum--; i=mkstick[MKSsum].lastid; } else while(bkstick[i].length==bkstick[1+i].length && i<BKsum)i++; } else if(mkstick[MKSsum].length+bkstick[i].length>MKlength) { i=mkstick[MKSsum].lastid; mkstick[MKSsum].length-=bkstick[i].length; mkstick[MKSsum].lastid=bkstick[i].preid; bkstick[i].preid=-2; if(mkstick[MKSsum].lastid==-1) { MKSsum--; i=mkstick[MKSsum].lastid; } else while(bkstick[i].length==bkstick[1+i].length && i<BKsum)i++; } else { mkstick[MKSsum].length+=bkstick[i].length; bkstick[i].preid=mkstick[MKSsum].lastid; mkstick[MKSsum].lastid=i; if(mkstick[MKSsum].length==MKlength) { i=0; MKSsum++; } } } } cout<<MKlength<<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