POJ 3273 Monthly Expense】的更多相关文章

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(…
题目传送门 /* 题意:分成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二分查找(最大值最小化问题) 题目: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…
题目: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…
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我们转化为求 满足该函数的 最小mid.即最小化最大值,可以通过二分搜索来做,要注意二分的边界.WR了好几次. 代码: #include<iostream> #include<string> #include<cstdlib> #include<cstdio> u…
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…
传送门 Time Limit: 2000MS Memory Limit: 65536K 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)…