POJ-3273 Monthly Expense 解题报告
来源:互联网 发布:超级seo外链工具 编辑:程序博客网 时间:2024/06/03 12:18
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 5
100
400
300
100
500
101
400
Sample Output
500
Hint
//STATUS:C++_AC_110MS_512K#include<stdio.h>const int MAXN=100010;int judge(int mid);int mon[MAXN],N,M;int main(){//freopen("in.txt","r",stdin);int i,low,mid,high,tot;while(~scanf("%d%d",&N,&M)){ low=0x80000000;for(i=0,high=1;i<N;i++){scanf("%d",&mon[i]);high+=mon[i];if(mon[i]>low)low=mon[i];}while(high-low!=1){mid=(low+high)/2;tot=judge(mid);if(tot>M)low=mid;else high=mid;}mid=judge(low)<=M?low:high; //这里要注意printf("%d\n",mid);}return 0;}int judge(int mid) //计算M{int i,tot,s,count;for(i=0,tot=0;i<N;count==1?i++:0){for(s=0,count=0;i<N;i++){s+=mon[i];count++;if(s>mid)break;}tot++;}return tot;}
- POJ-3273 Monthly Expense 解题报告
- POJ-3273 Monthly Expense 解题报告
- POJ 3273 Monthly Expense 解题报告(二分枚举)
- Monthly Expense解题报告
- Monthly Expense解题报告
- poj3273 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
- 黑马程序员训练营--c#中的构造方法
- STL库整理(map、set、vector、list、stack、queue、deque、priority_queue)
- KMP算法 (摘自matrix67大神博客)
- POJ_3347 Snowflake Snow Snowflakes 解题报告
- linux安装mysql二进制文件tar.gz
- POJ-3273 Monthly Expense 解题报告
- jquery获得ueditor内容并将数据发给服务器
- LAMP介绍
- 关于close与shutdown的区别
- 一位ACMer过来人的心得
- 常见hash算法的原理
- 黑马程序员_JavaAPI下
- 使用JQuery实现分页功能
- 从头到尾彻底解析Hash 表算法