【POJ 3273】 Monthly Expense (二分)】的更多相关文章

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…
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(…
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 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include <string.h> int n, m; ]; bool judge(int x) { , cnt = ; ; i < n; i++) { if(money + a[i] <= x) money += a[i]; else { money = a[i]; cnt++; } } if(c…
//最大值最小 //天数的a[i]值是固定的 不能改变顺序 # include <algorithm> # include <string.h> # include <stdio.h> using namespace std; int n,m; int a[100010]; int judge(int x) { int ans=1;//分成了几组 int tmp=0; for(int i=0;i<n;i++) { tmp+=a[i]; if(tmp>x) {…
题目传送门 /* 题意:分成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) { ,…
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…
题目: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…
题意:给出n天的花费,需要将这n天的花费分成m组,使得每份的和尽量小,求出这个最小的和 看题目看了好久不懂题意,最后还是看了题解 二分答案,上界为这n天花费的总和,下界为这n天里面花费最多的那一天 如果mid>=m,说明mid偏小,l=mid+1, 如果mid<m,说明mid偏大,r=mid, #include<iostream> #include<cstdio> #include<cstring> #include <cmath> #inclu…
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我们转化为求 满足该函数的 最小mid.即最小化最大值,可以通过二分搜索来做,要注意二分的边界.WR了好几次. 代码: #include<iostream> #include<string> #include<cstdlib> #include<cstdio> u…