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 |
我受不了了,我提交了不下50次,但怎么都是错? 发现不出来我的代码: 谁帮帮我 #include <iostream> #include <algorithm> using namespace std; #define NUM 100002 int T[NUM]; double Cost[NUM]; //烤的时间 int N, K; int make(double a) { int tmp = (int)a; if( a == (double)tmp) return tmp; return tmp+1; } int work() { int mid ,max = T[0],min = (T[0] ) / K; int i, tmp; double TT; while(true){ //几十次而已 if(min ==max) return min; mid = (min + max)/2; // 假设需要时间是mid TT = (double)( mid)/(double)(K-1); // (T[i]- rst)/(K-1) i=0; tmp=0; while(i<N){ // 有可能10万 if( T[i] <= mid ){ //不用烤 break; } tmp +=make( Cost[i] - TT); // 纯粹烤的时间!怎么大于max了? if( tmp>mid+1 ) break; i++; } if(tmp ==mid) //刚好 return tmp; if( tmp == mid+1) //也可以结束 return mid+1; if(min == (max-1) && tmp>min) //说明rst ==min 不行 return max; if( tmp > mid+1) //说明 mid小了 min = mid; else if( tmp < mid) //说明 mid 大了 max = mid; } return mid; } bool greater(const int & m1, const int & m2) { return m1 > m2; } void init() { sort(T,T+N,greater); int i=0; while(i<N){ Cost[i] = (double)(T[i] ) /(double) (K-1); // (T[i] - rst) / (K-1) i++; } } int main() { // freopen("C:\\makedata.txt","r",stdin); // freopen("C:\\ACMData.txt","r",stdin); int p; int rst =0; while(scanf("%d", &N)!=EOF){ p=0; while(p<N){ scanf("%d", &T[p]); p++; } scanf("%d", &K); init(); if( K==1) rst = T[0]; else rst = work(); printf("%d\n",rst); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator