POJ 3273 Monthly Expense 二分枚举
题目:http://poj.org/problem?id=3273
二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解。。
#include <stdio.h>
#include <string.h> int n, m;
int a[]; bool judge(int x)
{
int money = , cnt = ;
for(int i = ; i < n; i++)
{
if(money + a[i] <= x)
money += a[i];
else
{
money = a[i];
cnt++;
}
}
if(cnt > m)
return ;
else return ;
} int main()
{
int low = , high = ;
scanf("%d %d", &n, &m);
for(int i = ; i < n; i++)
{
scanf("%d", &a[i]);
if(low < a[i])
low = a[i];
high += a[i];
}
int mid = (low + high) / ;
while(low < high)
{
if(judge(mid))
high = mid - ;
else low = mid + ;
mid = (low + high) / ;
}
printf("%d\n", mid);
return ;
}
POJ 3273 Monthly Expense 二分枚举的更多相关文章
- POJ 3273 Monthly Expense二分查找[最小化最大值问题]
POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...
- POJ 3273 Monthly Expense(二分查找+边界条件)
POJ 3273 Monthly Expense 此题与POJ3258有点类似,一开始把判断条件写错了,wa了两次,二分查找可以有以下两种: ){ mid=(lb+ub)/; if(C(mid)< ...
- POJ 3273 Monthly Expense(二分答案)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 36628 Accepted: 13620 Des ...
- poj 3273 Monthly Expense (二分)
//最大值最小 //天数的a[i]值是固定的 不能改变顺序 # include <algorithm> # include <string.h> # include <s ...
- 二分搜索 POJ 3273 Monthly Expense
题目传送门 /* 题意:分成m个集合,使最大的集合值(求和)最小 二分搜索:二分集合大小,判断能否有m个集合. */ #include <cstdio> #include <algo ...
- poj 3273 Monthly Expense(贪心+二分)
题目:http://poj.org/problem?id=3273 题意:把n个数分成m份,使每份的和尽量小,输出最大的那一个的和. 思路:二分枚举最大的和,时间复杂度为O(nlog(sum-max) ...
- [ACM] POJ 3273 Monthly Expense (二分解决最小化最大值)
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 14158 Accepted: 5697 ...
- POJ 3273 Monthly Expense 【二分答案】
题意:给出n天的花费,需要将这n天的花费分成m组,使得每份的和尽量小,求出这个最小的和 看题目看了好久不懂题意,最后还是看了题解 二分答案,上界为这n天花费的总和,下界为这n天里面花费最多的那一天 如 ...
- poj 3273 Monthly Expense (二分搜索,最小化最大值)
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...
随机推荐
- UVA Knight Moves
题目例如以下: Knight Moves A friend of you is doing research on the Traveling Knight Problem (TKP) where ...
- iOS开发多线程篇---atomic nonatomic区别
摘要 atomic和nonatomic区别用来决定编译器生成的getter和setter是否为原子操 作.atomic提供多线程安全,是描述该变量是否支持多线程的同步访问,如果选择了atomic 那么 ...
- PERCONA-TOOLKIT 工具的安装与使用1
-c times Sun Jul :: CST Tracing process ID total pread read pwrite write fsync open close lseek fcnt ...
- iOS 网络编程:NSURLSession
NSURLSession类和相关的类提供很多API来下载HTTP的内容.这些API提供多种delegate协议来支持验证和执行后台下载任务. 1 URL Session 设计概念 Session中的任 ...
- Linux下pcapy的安装问题
在安装pcapy包的时候 cd pcapy-0.10.8/ python setup.py install 报错 error trying to exec ‘cc1plus’: execvp: No ...
- freewrap——将tcl/tk脚本转变为可执行文件
FreeWrap可以把TCL/TK的脚本和二进制文件打包成应用程序,FreeWrap将所有的文件组合成一个单独的可执行文件. FreeWrap的原理是把脚本和tcl/tk解释器和库文件都打包 ...
- js事件3
一.loading——(用来加载位于网页中的文件,而非本地的) 例子: <!doctype html> <html lang="en"> <head& ...
- nofollow标签如何使用
“nofollow”的意思是不传递权重,向网站站长提供了一种方式,即告诉搜索引擎“不要追踪此网页上的链接”或“不要追踪此特定链接”. nofllow的形式 1.<meta name=" ...
- 20151209jquery学习笔记Ajax 代码备份
/*$(function () { $("input").click(function() { $.ajax({ type:'POST', url:'test.php', data ...
- 转载---SQL Server XML基础学习<2>之--FOR XML AUTO/RAW
本文主要介绍FOR XML 的 AUTO 模式和 RAW 模式 --AUTO 模式将查询结果以嵌套 XML 元素的方式返回.这不能较好地控制从查询结果生成的 XML 的形式. --如果要生成简单的层次 ...