Description Farmer John ≤ moneyi ≤ ,) that he will need to spend each day over the next N ( ≤ N ≤ ,) days. FJ wants to create a budget ≤ M ≤ N) fiscal periods called or more consecutive days. Every day is contained in exactly one fajomonth. FJ's goal…
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我们转化为求 满足该函数的 最小mid.即最小化最大值,可以通过二分搜索来做,要注意二分的边界.WR了好几次. 代码: #include<iostream> #include<string> #include<cstdlib> #include<cstdio> u…
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 天,第 i 天会有 a[ i ] 的花费: 将这 N 天分成 M 份,每份包含 1 天或连续的多天: 每份的花费为包含的天数花费的加和,求最大花费的最小值. 题解: 二分搜索答案. AC代码: #include<iostream> #include<cstdio> using namespace std; ; int N,M; int totMoney;…
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…
题目传送门 /* 题意:分成m个集合,使最大的集合值(求和)最小 二分搜索:二分集合大小,判断能否有m个集合. */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int n, m; bool check(int tot) { ,…
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)<=m) ub=mid; ; //此时下限过小 } out(ub);//out(lb) 我一开始是写的下面这种,下面这种要单独判断lb和ub的值,因为用下面这种判断lb,ub都可能成立 ){ mid=(lb+ub)/; if(C(mid)<=m) ub=mid; else lb=mid; } if(C(…
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense 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 ≤ mon…
Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14158   Accepted: 5697 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 r…
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36628 Accepted: 13620 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 reco…
题目:http://poj.org/problem?id=3273 题意:把n个数分成m份,使每份的和尽量小,输出最大的那一个的和. 思路:二分枚举最大的和,时间复杂度为O(nlog(sum-max)); 一道很好的题. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace s…