xiaozhu2007
全部博文(103)
2008年(77)
2007年(26)
xiaobo20
cynthia
浪花小雨
GLM89122
Mr_Ran
sun2011y
feel_hyq
tinnal
竟成007
lovebing
分类: C/C++
2008-03-10 22:26:43
#include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { int N, K, num, mid; int i; int low = 0, high = 10000000; int l[10000]; int best = 0; float f; int *p = NULL; scanf("%d %d", &N, &K); p = (int *)malloc(N * sizeof(int)); if(p == NULL){ perror("malloc error"); exit(1); } for(i = 0; i < N; i++){ scanf("%f", &f); p[i] = f*100; } while(low <= high){ num = 0; mid = (low+high)/2; if(!mid){ break; } for(i = 0; i < N; i++){ num += p[i]/mid; if((num >= K) && (mid > best)){ best = mid; } } if(num >= K){ low = mid + 1; } else{ high = mid - 1; } } printf("%.2f\n", (float)best/100); exit(0); }
上一篇:优化代码的技巧
下一篇:Prob 1003 Hangover
登录 注册