POJ 3273 Monthly Expense
来源:互联网 发布:动易cms如何升级 编辑:程序博客网 时间:2024/05/20 00:10
http://poj.org/problem?id=3273
将数列中的元素分组 使得分组后和的最大值最小 采用二分答案的方法穷举。
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;int N,M,a[100010],ans;bool check(int mid){ int sum = 0,cnt = 1; for(int i=1; i<=N; i++){ if(sum + a[i] <= mid) sum += a[i]; else{ sum = a[i]; cnt++; } } return cnt <= M;}int main(){// freopen("in.txt", "r", stdin); scanf("%d%d",&N,&M); int sum = 0,left = 0, right; for(int i=1; i<=N; i++){ scanf("%d",&a[i]); sum += a[i]; left = max(left, a[i]); } right = sum; while(left <= right){ int mid = (left + right) >> 1; if(check(mid)){ ans = mid; right = mid - 1; } else left = mid + 1; } printf("%d\n",ans);}
0 0
- poj 3273 Monthly Expense
- poj-3273 Monthly Expense
- poj 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ-3273-Monthly Expense
- POJ 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ - 3273 Monthly Expense
- POJ-3273-Monthly Expense
- POJ 3273 Monthly Expense
- C++程序员必看书单
- 使用linux遇到的一些问题
- 算法摘记 拓扑排序
- Linux设备驱动_概述(1)
- 用c语言生成xml文件
- POJ 3273 Monthly Expense
- C++ 值传递、指针传递、引用传递详解
- 五险一金
- SQL汇总
- 当前不少入道的前端工程师大都是转行而来
- [android源码下载索引贴】微信+二维码那都不是事......
- MMI SS USSD扫盲贴
- C语言终极面试宝典_C语言面试必备
- oracle 查看用户,用户权限,用户表空间,用户默认表空间