Divide and Conquer:Monthly Expense(POJ 3273)
题目大意:不废话,最小化最大值
还是直接套模板,不过这次要注意,是最小化最大值,而不是最大化最小值,判断的时候要注意
联动3258
#include <iostream>
#include <functional>
#include <algorithm> using namespace std; static int money_set[]; void Search(const int, const int, const int);
bool C(const int, const int, const int); int main(void)
{
int days, set_sum;
while (~scanf("%d%d", &days, &set_sum))
{
for (int i = ; i < days; i++)
scanf("%d", &money_set[i]);
Search(days, set_sum, );
}
return ;
} void Search(const int days, const int set_sum,const int max_m)
{
int lb = , rb = max_m, mid; while (rb - lb > )
{
mid = (rb + lb) / ;
if (C(mid, set_sum, days))//二分逼近,最后的rb即为所求
rb = mid;
else
lb = mid;
}
printf("%d\n", rb);
} bool C(const int x, const int set_sum, const int days)
{
//这次是最小化最大值,注意变通
int tmp_m, pos = , uesd; for (uesd = ; pos < days && uesd < set_sum; uesd++)
{
for (tmp_m = ; pos < days && money_set[pos] + tmp_m <= x; pos++)
{
tmp_m += money_set[pos];
if (x < money_set[pos])
return false;
}
}
if (uesd < set_sum ||(uesd == set_sum && pos == days))
return true;
else return false;
}
Divide and Conquer:Monthly Expense(POJ 3273)的更多相关文章
- Divide and conquer:Telephone Lines(POJ 3662)
电话线 题目大意:一堆电话线要你接,现在有N个接口,总线已经在1端,要你想办法接到N端去,电话公司发好心免费送你几段不用拉网线,剩下的费用等于剩余最长电话线的长度,要你求出最小的费用. 这一看又是一个 ...
- Monthly Expense POJ 二分
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
- Divide and conquer:K Best(POJ 3111)
挑选最美的珠宝 题目大意:挑选k个珠宝使得∑a/∑b最大,输出组合数 最大化平均值的标准题型,二分法就好了,一定要注意范围(10e-7),如果是10e-8就会tle,10e-6就是wa #inclu ...
- Divide and conquer:Dropping tests(POJ 2976)
最大化平均值 题目大意:给定你n个分数,从中找出k个数,使∑a/∑b的最大值 这一题同样的也可以用二分法来做(用DP会超时,可见二分法是多么的实用呵!),大体上是这样子:假设最大的平均值是w,那么题目 ...
- Divide and conquer:Aggressive Cows(POJ 2456)
侵略性的牛 题目大意:C头牛最大化他们的最短距离 常规题,二分法即可 #include <iostream> #include <algorithm> #include < ...
- Divide and Conquer:Cable Master(POJ 1064)
缆绳大师 题目大意,把若干线段分成K份,求最大能分多长 二分法模型,C(x)就是题干的意思,在while那里做下文章就可以了,因为这个题目没有要求长度是整数,所以我们要不断二分才行,一般50-100次 ...
- Divide and Conquer:River Hopscotch(POJ 3258)
去掉石头 题目大意:一群牛在河上的石头上跳来跳去,现在问你如何通过去掉M个石头,使得牛跳过石头的最短距离变得最大? 这一题比较经典,分治法的经典,二分法可以很方便处理这个问题,我们只要明白比较函数这 ...
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- 二分搜索 POJ 3273 Monthly Expense
题目传送门 /* 题意:分成m个集合,使最大的集合值(求和)最小 二分搜索:二分集合大小,判断能否有m个集合. */ #include <cstdio> #include <algo ...
随机推荐
- 配置 nginx server 出现nginx: [emerg] "root" directive is duplicate in /etc/nginx/server/blogs.conf:7
在配置nginx 虚拟机时,执行 sudo /usr/sbin/nginx -t 报下面的错误: nginx: [emerg] nginx: configuration file /etc/nginx ...
- 如何判断一个变量是否是utf-8
//判断传入的字符是否是utf-8 function is_utf8($word){ if (preg_match("/^([".chr(228)."-" ...
- php apache用户写文件夹权限设置
php一般是以apache用户身份去执行的,把apache加入到存储你文件的父文件夹属组里去,然后改该父文件夹权限为775,这样属组成员就有写的权限,而apache属于这个组就可以改写该目录下所有文件 ...
- [译]在AngularJS中何时应该使用Directives,Controllers或者Service
原文: http://kirkbushell.me/when-to-use-directives-controllers-or-services-in-angular/ Services Servic ...
- SQL--表分区
use Test --.创建数据库文件组>>alter database <数据库名> add filegroup <文件组名> ALTER DATABASE TE ...
- web 开发前端学习
调试插件:http://www.getpostman.com/ http://bootstrap.evget.com/javascript.html bootstrap: http://www.bo ...
- 修改Ubuntu12.04 左侧启动器Launcher图标大小,以及如何隐藏启动器?
在 VirtualBox 中安装了 Ubuntu 12,一直使用 2D 桌面,3D桌面没用上,估计是电脑配置低的问题. 左边启动器的图标特别大,占据了很多的桌面空间,打算调小点.奇怪的是,在“系统设置 ...
- eclipse安装spring插件
1.打开eclipse点击help,点击about eclipse 2.点击最左侧图票查看eclipse版本 3.查看版本 4.进入http://spring.io/tools/sts/all,选择适 ...
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- HNU 12885 Bad Signal(模拟)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12885&courseid=274 解题报告:一共有n个 ...