OpenJugde - 2774:木材加工

来源:互联网 发布:中国被禁纪录片 知乎 编辑:程序博客网 时间:2024/04/27 13:24

题目链接:

http://bailian.openjudge.cn/practice/2774


Version 1.0 (2014-11-01)

Memory = 260 kb

Time = 0 ms

#include <stdio.h>int Lens[10000];int n, Count;int TotalLen;int findmax(int l, int r){if (r - l <= 1)return l;int ctry = (l + r) >> 1;int ctmp = 0;for (int i = 0; i < Count; i++)ctmp += Lens[i] / ctry;if (ctmp >= n) return findmax(ctry, r);else return findmax(l, ctry);}int main(){scanf("%d %d", &Count, &n);for (int i = 0; i < Count; i++) {scanf("%d", Lens + i);TotalLen += Lens[i];}if (TotalLen < n)printf("0");else if (TotalLen < 2 * n)printf("1");else printf("%d", findmax(2, TotalLen / n));return 0;}


0 0