POJ 3273 Monthly Expense (二分搜索)
来源:互联网 发布:流量联网控制软件 编辑:程序博客网 时间:2024/05/18 08:42
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
跟上一题类似 也是选出m个连续day 使得fajmonth小于等于二分的答案
AC代码如下:
//// POJ 3273 Monthly Expense//// Created by TaoSama on 2015-04-24// Copyright (c) 2015 TaoSama. All rights reserved.//#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;const int N = 1e5 + 10;int n, m, a[N];bool check(int x) { int last = 0; for(int i = 1; i <= m; ++i) { int idx = last + 1, sum = a[idx]; while(idx <= n && sum < x) { ++idx; sum += a[idx]; } if(idx == n + 1) return false; last = idx - 1; } return true;}int main() {#ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); cin >> n >> m; for(int i = 1; i <= n; ++i) { cin >> a[i]; } int l = 0, r = 1e9 + 1; while(l + 1 < r) { int mid = 0LL + l + r >> 1; if(check(mid)) l = mid; else r = mid; } cout << l << '\n'; 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(二分)
- 怎么删除node_modules等Node安装包
- PHP开发环境的搭建
- oracle学习(一)
- 1039. 到底买不买(20):map应用
- css 条件注释区分非IE浏览器
- POJ 3273 Monthly Expense (二分搜索)
- Handler可能导致的内存泄漏及其优化
- 关于VC++6.0加载控件出现Unable to register this add-in because its DllRegisterServer returns an error 的解决方法
- JavaScript实现异步调用例子
- jQuery制作菜单
- 检测C++的内存泄漏(win7 64 vs2010)
- Windows环境下lib和dll的区别和联系详细
- - query.ajax通过name获取value值方法、
- 为什么你总是无法摆脱痛苦?