poj 3273 Monthly Expense
来源:互联网 发布:php erp 编辑:程序博客网 时间:2024/05/29 01:53
用二分,详细思路见注释。
#include <stdio.h>#include <stdlib.h>int a[100000+10];int main(){ int n,m,group,high=0,mid,low=0,sum,sum_max,t=0; int i; scanf("%d %d",&n,&m); for(i=0; i<n; i++) { scanf("%d",&a[i]); high+=a[i];//所有天数的花费和作为最大值,相当于只分成一个组 if(a[i]>low) low=a[i];//花费最多的那一天的值作为最小值,相当于分成n组 } while(low<high)//在low==high之前可能有分组情况为m的,但是不能保证值最小 { group=1; mid=(low+high)/2; sum=0; sum_max=0; for(i=0; i<n; i++) { sum+=a[i]; if(sum>mid) { sum=a[i]; group++; } } if(group<=m) high=mid; else low=mid+1; } printf("%d\n",low); return 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
- hdu 2181 哈密顿绕行世界问题 - 搜索
- Burning Midnight Oil
- poj 1979 Red and Black - bfs
- 分析函数
- hdu 1241 Oil Deposits - bfs
- poj 3273 Monthly Expense
- poj 2785 4 Values whose Sum is 0
- iOS7设置状态栏颜色
- hdu 1874 畅通工程续 - 最短路
- hdu 1869 六度分离
- Android WebView常见问题及解决方案汇总
- hdu 2680 Choose the best route
- hdu 3790 最短路径问题
- poj 1321 棋盘问题