poj3273 Monthly Expense(二分搜索)
https://vjudge.net/problem/POJ-3273
认真审题,代码仔细!!ans的初值应该是1
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
#define INF 0x3f3f3f3f
typedef unsigned long long ll;
using namespace std;
ll n, m, a[];
ll C(ll x)
{
ll ans=, sum=;//认真审题啊!!ans的初值是1
for(int i = ; i < n; i++){
sum += a[i];
if(sum > x){
if(a[i]>x) return ;//单个就>
sum = a[i];
ans++;
}
if(ans>m){
return ;
}
}
return ;
}
int main()
{
while(cin >> n >> m){
for(int i = ; i < n; i++){
cin >> a[i];
}
ll lb = , ub = INF;
while(ub-lb>){
ll mid = (lb+ub)>>;
if(C(mid)){
ub = mid;
}
else{
lb = mid;
}
}
cout << ub << endl;
}
return ;
}
poj3273 Monthly Expense(二分搜索)的更多相关文章
- POJ3273 Monthly Expense 2017-05-11 18:02 30人阅读 评论(0) 收藏
Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25959 Accepted: 10021 ...
- POJ-3273 Monthly Expense (最大值最小化问题)
/* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...
- POJ3273 Monthly Expense —— 二分
题目链接:http://poj.org/problem?id=3273 Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Tota ...
- poj 3273"Monthly Expense"(二分搜索+最小化最大值)
传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 天,第 i 天会有 a[ i ] 的花费: 将这 N 天分成 M 份,每 ...
- poj 3273 Monthly Expense(二分搜索之最大化最小值)
Description Farmer John ≤ moneyi ≤ ,) that he will need to spend each day over the next N ( ≤ N ≤ ,) ...
- poj 3273 Monthly Expense (二分搜索,最小化最大值)
题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...
- POJ 3273 Monthly Expense(二分搜索)
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
- POJ3273 Monthly Expense
查看原题 边界,就是边界和思维,怎么有效的判断中间值是大了还是小了,以及准确的找到边界!一个<写成<=就前功尽弃,还特别难找到错误! #include <cstdio> #in ...
- OJ 21658::Monthly Expense(二分搜索+最小化最大值)
Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N< ...
随机推荐
- mysql8.0.11绿色版安装教程
解压到安装目录 在根目录建立data文件夹 建立my.ini文件 代码如下 # Other default tuning values # MySQL Server Instance Configur ...
- Linux(CentOS7)安装Tomcat
概述 Tomcat是运行Jsp文件的容器服务,能够处理URL请求,类似于IIS.相对于IIS,Tomcat可以部署到Linux.Windows.IOS等操作系统.这里主要整理将Tomcat部署到Lin ...
- sprintf补位
有的时候需要00001这样的字符串 来源却是Int的1 这个时候就可以用sprintf方法了 $i = 3; $a=sprintf("%08d", $i); echo $a; %0 ...
- haoi2018
题解: 题目相对其他省难一点 不过弱省省选知识点都这么集中的么.. 4道数学题... 1.[HAOI2018]奇怪的背包 这题考场做就gg了... 其实我想到了那个性质.. 就是这个一定要是gcd的倍 ...
- NEST - 返回部分文档
Selecting fields to return Version:5.x 英文原文地址:Selecting fields to return 有时候,不需要让 Elasticsearch 返回查询 ...
- rimraf node_modules 快速删除
npm install -g rimraf // 先进行全局安装 rimraf node_modules // 进行删除 -------------------------------- ...
- 1000. A+B Problem
Description Calculate a+b Input Two integer a,b (0<=a,b<=10) Output Output a+b Sample Input 1 ...
- day70 cookie & session 前后端交互分页显示
本文转载自qimi博客,cnblog.liwenzhou.com 概要: 我们的cookie是保存在浏览器中的键值对 为什么要有cookie? 我们在访问浏览器的时候,千万个人访问同一个页面,我们只要 ...
- miniui中可以设置是否让页面进行分页 <div id="datagrid1" class="mini-datagrid" style="width:100%" allowAlternating="true" showpager="true"/> 就是设置showpager属性为true
<div id="datagrid1" class="mini-datagrid" style="width:100%" allowA ...
- SparkException: Could not find CoarseGrainedScheduler or it has been stopped.
org.apache.spark.SparkException: Could not find CoarseGrainedScheduler or it has been stopped. at or ...