[Usaco07Mar&luogu2884]Monthly Expense
来源:互联网 发布:数据库建模培训 编辑:程序博客网 时间:2024/05/21 07:08
题目链接
题解:二分搞一搞
#include <iostream>#include <cstdio>#include <climits>using namespace std;#define INF INT_MAX-1000int n,m,l,r,mid,ans;int w[100005];bool ok(int x){ int s=0,k=1;//至少要有一组 for(int i=1;i<=n;i++) { if(w[i]>x) return false; s+=w[i]; if(s>x) s=w[i],k++; } return k<=m;}int main(){ cin>>n>>m; for(int i=1;i<=n;i++) scanf("%d",&w[i]); l=1;r=INF; while(l<=r) { mid=(l+r)>>1; if(ok(mid)) r=mid-1,ans=mid; else l=mid+1; } printf("%d\n",ans); return 0;}
0 0
- [Usaco07Mar&luogu2884]Monthly Expense
- Monthly Expense
- Monthly Expense
- Monthly Expense
- Monthly Expense
- pku3273 Monthly Expense
- Monthly Expense(二分)
- poj 3273 Monthly Expense
- poj-3273 Monthly Expense
- Monthly Expense解题报告
- POJ3273:Monthly Expense
- poj 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ3273:Monthly Expense(二分)
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ3273--Monthly Expense
- 几种list循环的方法
- 提高生产力:小雷之问和京东之答
- 高通工具QACT使用之MBDRC模块配置
- C/C++编程规范(一)命名篇
- hdu1069 Monkey and Banana dp
- [Usaco07Mar&luogu2884]Monthly Expense
- 没有上司的舞会
- 洛谷 p1478
- LeetCode No.84 Largest Rectangle in Histogram
- CodeLink计划
- 深入学习JavaScript: apply 方法 详解
- 2016.09.25日志
- 【面经】cvte二面
- tomcate 启动报错