POJ 3273 二分答案
思路:二分答案经典题吧。。。。注意边界就OK了
//By SiriusRen
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m,a[100050],ans;
bool check(int x){
int jy=0,temp=0;
for(int i=1;i<=n;i++){
if(a[i]+jy>x){
jy=0;
temp++;
if(temp>m)return 0;
}
jy+=a[i];
if(temp>=m||jy>x)return 0;
}
return 1;
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
int Left=0,Right=0x3fffffff;
while(Left<=Right){
int Mid=(Left+Right)>>1;
if(check(Mid))Right=Mid-1,ans=Mid;
else Left=Mid+1;
}
printf("%d\n",ans);
}
POJ 3273 二分答案的更多相关文章
- poj 1743 二分答案+后缀数组 求不重叠的最长重复子串
题意:给出一串序列,求最长的theme长度 (theme:完全重叠的子序列,如1 2 3和1 2 3 or 子序列中每个元素对应的差相等,如1 2 3和7 8 9) 要是没有差相等这个条件那就好办 ...
- poj 1064(二分答案)
传送门:Problem 1064 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有N条绳子,长度分别为 length[1,2,3,.. ...
- poj 3261 二分答案+后缀数组 求至少出现k次的最长重复子序列
#include "stdio.h" #define maxn 20010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int rank[ma ...
- POJ 3273 Monthly Expense 【二分答案】
题意:给出n天的花费,需要将这n天的花费分成m组,使得每份的和尽量小,求出这个最小的和 看题目看了好久不懂题意,最后还是看了题解 二分答案,上界为这n天花费的总和,下界为这n天里面花费最多的那一天 如 ...
- POJ 3273-Monthly Expense 求分组和的最小的最大值【二分答案】
题目链接:http://poj.org/problem?id=3273 题目大意:给出一个有n个数据的数组,将其分为连续的m份,找到一种分法,是的m份中最大一份总和最小 解题思路: 直接在答案的区间内 ...
- 字符串hash + 二分答案 - 求最长公共子串 --- poj 2774
Long Long Message Problem's Link:http://poj.org/problem?id=2774 Mean: 求两个字符串的最长公共子串的长度. analyse: 前面在 ...
- POJ 3104 Drying(二分答案)
题目链接:http://poj.org/problem?id=3104 ...
- POJ 1064 Cable master (二分答案)
题目链接:http://poj.org/problem?id=1064 有n条绳子,长度分别是Li.问你要是从中切出m条长度相同的绳子,问你这m条绳子每条最长是多少. 二分答案,尤其注意精度问题.我觉 ...
- POJ 3273 Monthly Expense 二分枚举
题目:http://poj.org/problem?id=3273 二分枚举,据说是经典题,看了题解才做的,暂时还没有完全理解.. #include <stdio.h> #include ...
随机推荐
- [Javascirpt] Developer-friendly Flow Charts with flowchart.js
Flowchart.js is a great tool for creating quick, simple flowcharts in a way that keeps you out of a ...
- bzoj 1600 & Usaco 月赛 2008 建造栅栏 题解
[原题] 1600: [Usaco2008 Oct]建造栅栏 Time Limit: 5 Sec Memory Limit: 64 MB Submit: 785 Solved: 443 [Subm ...
- uva 10641 (来当雷锋的这回....)
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using ...
- vue中router-link的click事件失效的解决办法
title: vue中router-link的click事件失效的解决办法 toc: false date: 2018-12-04 16:28:49 categories: Web tags: vue ...
- jq操作属性,元素,样式,事件
操作属性: 单个 $('选择器').attr('属性名','属性值'); 多个 $('选择器').attr({'属性名':'属性值','':''}); eg: $('#a1').attr('flag' ...
- shell-1.shell概述、2.shell脚本执行方式
目录
- swift语言点评十七-Designated Initializers and Convenience Initializers
Swift defines two kinds of initializers for class types to help ensure all stored properties receive ...
- js函数参数理解
eg: function setName(obj){ obj.name = "Nicholas"; obj = new Object(); obj.name = "Gre ...
- ActiveMQ学习笔记(17)----Message高级特性(一)
1. Messaage Properties ActiveMQ支持很多消息属性,具体可以参考 http://activemq.apache.org/activemq-message-propertie ...
- ZBrush软件特性之3D图层
用过Photoshop的小伙伴都知道图层的概念,在Photoshop中可以创建许许多多的图层,在每一图层中又可以分别编辑图像信息.ZBrush®中的3D图层,也可以简单理解成Photoshop中的图层 ...