链接:http://poj.org/problem?id=3273

题意:FJ想把n天分成m组,每组是连续的,同一组的花费加起来算,求所分组情况中最高花费的最低值

思路:二分答案。二分整数范围内的花费,每次去check一下,check的过程贪心处理即可。

AC代码:

 #include<iostream>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int N,M;
vector<int> day;
bool check(int x){
int cnt = ;//cnt记录组数
int cost = ;//cost记录一组的花费
for(int i = ;i<day.size() ;i++){
if(day[i]>x){
return false;//如果某一天的花费大于x,直接返回false
}
if(cost+day[i]>x){//如果花费超过x,那么就加一组
cnt++;
cost = day[i];
continue;
}
cost+=day[i];
}
return cnt<=M;
}
int main(){
while(cin>>N>>M){
day.clear() ;
for(int i = ;i<N;i++){
int t;cin>>t;
day.push_back(t);
}
int l = ,r = 1e9+;
int mid;
while(l<r){
mid = (l+r)>>;
if(check(mid)){
r = mid ;
}
else{
l = mid + ;
}
}
cout<<l<<endl;
}
return ;
}

POJ3273 Monthly Expense (二分最小化花费)的更多相关文章

  1. POJ-3273 Monthly Expense (最大值最小化问题)

    /* Monthly Expense Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10757 Accepted: 4390 D ...

  2. Monthly Expense(最大值最小化问题)

                                                                                POJ-3273                 ...

  3. OJ 21658::Monthly Expense(二分搜索+最小化最大值)

        Description Farmer John是一个令人惊讶的会计学天才,他已经明白了他可能会花光他的钱,这些钱本来是要维持农场每个月的正常运转的.他已经计算了他以后N(1<=N< ...

  4. POJ3273 Monthly Expense —— 二分

    题目链接:http://poj.org/problem?id=3273   Monthly Expense Time Limit: 2000MS   Memory Limit: 65536K Tota ...

  5. poj 3273"Monthly Expense"(二分搜索+最小化最大值)

    传送门 https://www.cnblogs.com/violet-acmer/p/9793209.html 题意: 有 N 天,第 i 天会有 a[ i ] 的花费: 将这 N 天分成 M 份,每 ...

  6. POJ 3273 Monthly Expense二分查找[最小化最大值问题]

    POJ 3273 Monthly Expense二分查找(最大值最小化问题) 题目:Monthly Expense Description Farmer John is an astounding a ...

  7. POJ_3273_Monthly_Expense_(二分,最小化最大值)

    描述 http://poj.org/problem?id=3273 共n个月,给出每个月的开销.将n个月划分成m个时间段,求m个时间段中开销最大的时间段的最小开销值. Monthly Expense ...

  8. 【POJ 3273】 Monthly Expense (二分)

    [POJ 3273] Monthly Expense (二分) 一个农民有块地 他列了个计划表 每天要花多少钱管理 但他想用m个月来管理 就想把这个计划表切割成m个月来完毕 想知道每一个月最少花费多少 ...

  9. POJ_3104_Drying_(二分,最小化最大值)

    描述 http://poj.org/problem?id=3104 n件衣服,第i件衣服里面有水a[i],自然风干每分钟干1个水,用吹风机每分钟干k个水,但是同时只能对一件衣服使用吹风机,求干完所有衣 ...

随机推荐

  1. 【机器学习】使用CNN神经网络实现对图片分类识别及模型转换

    仅做记录,后面慢慢整理 训练函数: from skimage import io, transform # skimage模块下的io transform(图像的形变与缩放)模块 import glo ...

  2. [Python]PyCharm在创建py文件时自动添加头部注释

    在Pycharm主界面找到 File ----->> Setting ----->> Editor ----->> File and Code Templates ...

  3. git签名设置

    作用:只区分不同开发人员的身份 一.项目级别/仓库级别:仅在当前本地库范围内有效 签名设置用户名(UserName)和邮箱(User@email),邮箱可以是任意邮箱(无效邮箱也可以) git con ...

  4. Mybatis的增删改和log4j的基础配置

    带条件查询 mapper文件的内容: <select id="getSelectElectron" resultType="electron"> s ...

  5. Python 教你 4 行代码开发新闻网站通用爬虫

    \ ​ GNE(GeneralNewsExtractor)是一个通用新闻网站正文抽取模块,输入一篇新闻网页的 HTML, 输出正文内容.标题.作者.发布时间.正文中的图片地址和正文所在的标签源代码.G ...

  6. List和DataTable互转

    /// <summary> /// List和DataTable互转 /// </summary> static class ListUtility { /// <sum ...

  7. Jquery实现挂号平台首页源码

    带二级导航.轮播海报.二级联动.搜索功能.Tab选项卡 按照国际惯例先放图 index.html <!DOCTYPE html> <html lang="zh-cn&quo ...

  8. [PAT] A1021 Deepest Root

    [题目大意] 给出n个结点和n-1条边,问它们能否形成一棵n个结点的树,如果能,从中选出结点作为树根,使整棵树的高度最大.输出所有满足要求的可以作为树根的结点. [思路] 方法一:模拟. 1 连通.边 ...

  9. Leetcode Week5 Maximum Sum Circular Subarray

    Question Given a circular array C of integers represented by A, find the maximum possible sum of a n ...

  10. react admin

    react admin 管理后台的快速创建方式