POJ - 3273 Monthly Expense(二分)
来源:互联网 发布:hello软件 编辑:程序博客网 时间:2024/06/06 03:20
Description
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Input
Lines 2..N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Sample Input
7 5100400300100500101400
Sample Output
500
Hint
If Farmer John schedules the months so that the first two days are a month, the third and fourth are a month, and the last three are their own months, he spends at most $500 in any month. Any other method of scheduling gives a larger minimum monthly limit.
题意:给你n个数,让分成m组,每组必须是连续的一些数,求每组的和的最大值最小。
确定好数据的上界为所有数的和,数据的下届为最大的数,如此用二分一一处理即可,注意这里的数据可能会超int,所有用long long,同时最后分组的情况要加入进来,不要遗漏了。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long LL;const int MAXN = 1e5 + 5;const int INF = 0x3f3f3f3f;int N, M;LL A[MAXN];bool C(int m) {LL res = 0, va = 0;for(int i = 0; i < N; i ++) {va += A[i];if(va > m) {va = A[i];res ++;}if(res > M) return false;}res ++;if(res > M) return false;return true;}int main() {while(~scanf("%d%d", &N, &M)) {LL sum = 0, ma = 0;for(int i = 0; i < N; i ++) {scanf("%lld", &A[i]);sum += A[i];ma = max(ma, A[i]);}LL lb = ma - 1, ub = sum;while(ub - lb > 1) {int mid = (ub + lb) >> 1;if(C(mid)) {ub = mid;} else {lb = mid;}}printf("%lld\n", ub);}return 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(二分)
- jquery自动补全
- FloatingActionButton 浮动按钮
- 稠密矩阵 稀疏矩阵
- C#控制台基础 打开指定的文件夹后,第一眼看到的文件的名称,文件大小
- JMeter学习(七)聚合报告之 90% Line 正确理解
- POJ - 3273 Monthly Expense(二分)
- 快速排序
- 对象的生存与死亡
- Linked List Cycle
- 【POJ2367】
- 数据库事务ACID原则
- ffprobe使用详解
- TextInputLayout控件
- iOS进阶之UI利器Reveal(1)--Reveal的下载,安装和破解