【POJ】[3273]Monthly Expense
来源:互联网 发布:linux是什么系统 编辑:程序博客网 时间:2024/06/10 21:16
二分法
答案符合的条件是让
可以分的月数不大于m
注意一旦有单一元素超过x
则x肯定不是解
#include<stdio.h>int a[100200];int n,m;bool judge(int x) { int sum=0,cnt=1; for(int i=0; i<n; i++) { if(a[i]>x) return false; sum+=a[i]; if(sum>x) { cnt++; sum=a[i]; } } if(cnt>m) return false; else return true;}int main() { while(scanf("%d %d",&n,&m)!=EOF) { int l=0,r=0; for(int i=0; i<n; i++) { scanf("%d",&a[i]); r+=a[i]; } int mid,res; while(r>=l) { mid=(l+r)/2; if(judge(mid)) { res=mid; r=mid-1; } else l=mid+1; } printf("%d\n",res); } return 0;}
题目地址:【POJ】[3273]Monthly Expense
0 0
- poj 3273 Monthly Expense
- poj-3273 Monthly Expense
- poj 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ-3273-Monthly Expense
- POJ 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- poj 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ 3273 Monthly Expense
- POJ - 3273 Monthly Expense
- POJ-3273-Monthly Expense
- POJ 3273 Monthly Expense
- [编程题]地域划分
- Android RelativeLayout动态修改子控件位置(可连续拖动的View)
- 深度学习系列——windows平台下跑微软caffe实战之运行mnist,cifar10
- 在一个UILabel中实现不同的字体和颜色
- POJ 3468 A Simple Problem with Integers (树状数组)
- 【POJ】[3273]Monthly Expense
- (2.2.9)Groovy 介绍
- 对UIView 实例方法的探索
- LeetCode *** 210. Course Schedule II
- 定时自动启动任务crontab命令用法
- Shell 脚本知识回顾 (一) —— 基础篇
- 如何更改workbench的快捷键
- [CODEVS1090][NOIP2013]加分二叉树(树形dp)
- 入门Android开发--第一行代码--笔记系列(Service)