POJ3273 Monthly Expense 二分
来源:互联网 发布:网络球机接线图 编辑:程序博客网 时间:2024/05/21 18:01
Description
Farmer John is an astounding accounting wizard and has realized he might run out of money to run the farm. He has already calculated and recorded the exact amount of money (1 ≤ moneyi ≤ 10,000) that he will need to spend each day over the next N (1 ≤ N ≤ 100,000) days.
FJ wants to create a budget for a sequential set of exactly M (1 ≤ M ≤ N) fiscal periods called "fajomonths". Each of these fajomonths contains a set of 1 or more consecutive days. Every day is contained in exactly one fajomonth.
FJ's goal is to arrange the fajomonths so as to minimize the expenses of the fajomonth with the highest spending and thus determine his monthly spending limit.
Input
Lines 2..N+1: Line i+1 contains the number of dollars Farmer John spends on the ith day
Output
Sample Input
7 5100400300100500101400
Sample Output
500
Hint
Source
USACO 2007 March Silver
// 题意 把 7天分成 5组 要求连续 求出各种情况中分组中的最大值 要求这个最大值是各种情况下最小的
// 第一个二分吧
// ''这个最大值'' 一定在最大元素 和 所有数和之间 然后二分查找
#include<stdio.h>int n,m;int binaryg(int mid,int *a){ int sum=0; int group=1; for(int i=1; i<=n; i++) { sum+=a[i]; if(sum<=mid) continue; else { sum=a[i]; group++; } } if(group>m) return 1;//如果按这个数分组 组数大于m说明这个数小了 else return 0;}int main(){ int high,low,i,mid; int a[100010]; scanf("%d%d",&n,&m); high=0; low=0; for(i=1; i<=n; i++) { scanf("%d",&a[i]); high+=a[i]; if(low<a[i]) low=a[i]; } mid=(high+low)>>1; while(low<high) { if(binaryg(mid,a)) low=mid+1; else high=mid-1; mid=(low+high)>>1; } printf("%d\n",mid); return 0;}
- POJ3273:Monthly Expense(二分)
- POJ3273:Monthly Expense(二分)
- poj3273--Monthly Expense(二分)
- poj3273 Monthly Expense(二分)
- POJ3273 Monthly Expense 二分
- 二分 Monthly Expense poj3273
- POJ3273 Monthly Expense 二分搜索
- poj3273 Monthly Expense(二分)
- POJ3273:Monthly Expense(二分)
- POJ3273 Monthly Expense 二分查找
- poj3273-Monthly Expense典型的二分题目
- POJ3273 Monthly Expense(二分答案)
- Monthly Expense poj3273 (二分/最大值最小化)
- poj3273——Monthly Expense(二分)
- POJ3273:Monthly Expense
- POJ3273--Monthly Expense
- POJ3273 Monthly Expense
- poj3273 Monthly Expense
- HDU 5752 Sqrt Bo(水~)
- gdb 跟踪调试命令整理
- 微信 图文消息
- 关于未捕获异常的处理(WPF)
- mysql------事务
- POJ3273 Monthly Expense 二分
- eclipse关联spring源码
- 【华为 OJ 】求小球落地5次后所经历的路程和第5次反弹的高度
- 【MyBatis框架】mapper配置文件-关于动态sql
- 找不到winapifamily.h
- UrlRewriteFilter使用说明
- 设置ListView中的所有Item均不可点击
- fastjson使用方法简析
- 计算机视觉在安防、交通、机器人、无人车等领域的应用