Chinaunix首页 | 论坛 | 博客
  • 博客访问: 434709
  • 博文数量: 103
  • 博客积分: 5010
  • 博客等级: 大校
  • 技术积分: 971
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-11 17:22
文章分类
文章存档

2008年(77)

2007年(26)

我的朋友

分类: 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);
}

阅读(653) | 评论(0) | 转发(0) |
0

上一篇:优化代码的技巧

下一篇:Prob 1003 Hangover

给主人留下些什么吧!~~