poj_3273 Monthly Expense(二分穷举)
来源:互联网 发布:php木马扫描器 编辑:程序博客网 时间:2024/06/08 02:36
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 nextN (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 theith day
Output
Sample Input
7 5100400300100500101400
Sample Output
500
Hint
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <stack>#include <bitset>#include <queue>#include <set>#include <map>#include <string>#include <algorithm>#define FOP freopen("data.txt","r",stdin)#define FOP2 freopen("data1.txt","w",stdout)#define inf 0x3f3f3f3f#define maxn 100010#define mod 1000000007#define PI acos(-1.0)#define LL long longusing namespace std;int n, m;int a[maxn];bool judge(int mid){ int cot = 1, sum = 0; for(int i = 1; i <= n; i++) { if(sum+a[i] <= mid) sum += a[i]; else sum = a[i], cot++; } return cot <= m;}int main(){ while(~scanf("%d%d", &n, &m)) { for(int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = 0, r = 0, mid; for(int i = 1; i <= n; i++) { l = max(l, a[i]); r += a[i]; } while(l <= r) { mid = l + r >> 1; if(judge(mid)) r = mid-1; else l = mid+1; } printf("%d\n", mid); } return 0;}
- poj_3273 Monthly Expense(二分穷举)
- Monthly Expense(二分)
- Monthly Expense(二分)
- Monthly Expense--(二分)
- Monthly Expense (二分)
- Monthly Expense(二分)
- poj3273 Monthly Expense(二分)
- POJ3273:Monthly Expense(二分)
- POJ 3273 Monthly Expense(二分枚举)
- POJ 3273 - Monthly Expense(二分)
- POJ 3273 Monthly Expense(二分查找)
- poj 3273 Monthly Expense(二分+贪心)
- POJ 3273 Monthly Expense (二分搜索)
- POJ3273 Monthly Expense(二分答案)
- POJ 3273 Monthly Expense(二分)
- Monthly Expense(二分最值)
- poj-3273 Monthly Expense (二分)
- POJ 3273 Monthly Expense (二分搜索)
- javaIO流之常用IO流
- 论计算机基础的重要性
- 自定义标签
- linux/mac下将一个文件夹中所有文件从当前目录移动到另一目录下
- 二维数组的解疑
- poj_3273 Monthly Expense(二分穷举)
- 微软警告用户不要去随意修改 Linux 文件
- SQL触发器及视图
- 把自然数N分解成若干个互不相同的正整数,使乘积最大
- Jquery父子选择器基础用法
- 理解CSS中的块级格式化上下文转载于(https://segmentfault.com/a/1190000003068557#articleHeader6)
- Android 在获取View的width 和 heigt 时 = 0h
- 表单动态验证之原生Ajax
- UnityShader:MRT多重渲染