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 |
冰天雪地跪求高手指正错误 1505试过N多数据,郁闷了 #include <iostream> #include <stdlib.h> using namespace std; #define length 502 //typedef long long __int64; long long a[length]; int t,n,personNumber,bookNumber; long long sum,minV; void init(){ int i; sum=0; minV=0; cin>>bookNumber>>personNumber; for(i=0;i<bookNumber;i++){ scanf("%I64d",&a[i]); sum+=a[i]; if(a[i]>minV) minV=a[i]; } } int compute(long long maxValue){ int i,j; long long current; for(i=personNumber,j=bookNumber-1;j>=0&&i>0;i--){ current=0; for(;j>=0&¤t+a[j]<=maxValue;j--){ current+=a[j]; } if(j<0) break; } if(i>0){ return 1; } return 0; } int main(){ __int64 maxV,mid,value,current; int i,j; int record[length]; cin>>t; while(t--){ init(); maxV=sum; while(minV<maxV){ mid=(minV+maxV)/2; if(compute(mid)){ maxV=mid-1; value=mid; }else{ minV=mid+1; } } for(i=personNumber-1,j=bookNumber-1;i>0;i--){ current=0; for(;j>=0&¤t+a[j]<=value&&j>=i;j--){ current+=a[j]; } record[i]=j; } for(i=1,j=0;i<personNumber;i++){ for(;j<=record[i];j++) printf("%d ",a[j]); printf("/ "); } for(;j<bookNumber;j++){ printf("%d ",a[j]); } putchar('\n'); } system("PAUSE"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator