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 |
大牛们过来看看啦,该注意的地方都注意了,为何还是WA呢?#include <stdio.h> int end[100005]; void main() { int T,i,n; scanf("%d",&T); while(T--) { int yi,M,K; __int64 out; int min,left=0,right=100000000; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&end[i]); scanf("%d %d",&M,&K); if(K==1) { right=-1; for(i=0;i<n;i++) if(right<end[i])right=end[i]; } else { while(left<right) { int sg=0; min=(left+right)/2; out=M*min; if(M>n)out=n*min; for(i=0;i<n;i++) { if(end[i]>min) { yi=(end[i]-min+K-2)/(K-1);//向后推进K+2个位置,化解了有余数的情况 out-=(__int64)yi; if(yi>min)sg=1; } } if(out<0||sg==1)left=min+1; else right=min; } } printf("%d\n",right); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator