| ||||||||||
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 |
这题有bug吧,过去ac的程序现在也不行用了ac的代码试了下,也不行,蛋都碎了!!! 我已经神经质地把所有int8换成int64了,下面代码如有bug,求狠拍! --------------------------------------- #include <stdio.h> #include <algorithm> using namespace std; void sum_up(long long *ary, long long len, long long *sum) { sum[0] = ary[0]; for(long long i = 0; i < len; i ++) sum[i + 1] = sum[i] + ary[i + 1]; } bool validate(long long *ary, long long *sum, long long ary_len, long long frag_cnt, long long len) { if(frag_cnt <= 0) return true; if(ary_len == 0 && frag_cnt != 0) return false; if(sum[ary_len - 1] < frag_cnt * len) return false; long long consume = ary[ary_len - 1] / len; if(consume == 0) return false; return validate(ary, sum, ary_len - 1, frag_cnt - consume, len); } long long bin(long long *ary, long long *sum, long long ary_len, long long frag_cnt, long long begin, long long end) { if(end == begin) return begin; if(end - begin == 1) { if(validate(ary, sum, ary_len, frag_cnt, end)) return end; return begin; } long long middle = (begin + end) / 2; if(validate(ary, sum, ary_len, frag_cnt, middle)) return bin(ary, sum, ary_len, frag_cnt, middle, end); else return bin(ary, sum, ary_len, frag_cnt, begin, middle); } void calc(long long *ary, long long *sum, long long ary_len, long long frag_cnt) { if(!validate(ary, sum, ary_len, frag_cnt, 1)) { printf("0.00\n"); return; } long long max = sum[ary_len - 1] / frag_cnt; max = max > ary[ary_len - 1] ? ary[ary_len - 1] : max; long long result = bin(ary, sum, ary_len, frag_cnt, 1, max); double f = result / 100.0f; printf("%.2lf\n", f); } int main(void) { long long n, k; long long cables[10002]; long long sum[10002]; while(scanf("%lld %lld", &n, &k) != EOF) { double temp; for(long long i = 0; i < n; i ++) { scanf("%lf", &temp); cables[i] = (long long)((temp + 0.005) * 100); } sort(cables, cables + n); sum_up(cables, n, sum); calc(cables, sum, n, k); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator