poj3273 二分搜索
2012-07-26 23:53
155 查看
链接:http://poj.org/problem?id=3273
水题,不过第一次二分。
题解:http://zhenzxie.iteye.com/blog/1446986
水题,不过第一次二分。
题解:http://zhenzxie.iteye.com/blog/1446986
#include<stdio.h> #include<string.h> int day[100040]; int main() { int i,j,n,m,sum,max,mid,res; while(scanf("%d%d",&n,&m)>0) { sum=0; max=-1000; for(i=1;i<=n;i++) { scanf("%d",&day[i]); sum+=day[i]; max=(max>day[i])?max:day[i]; } while(max<sum) { mid=(max+sum)/2; for(i=2,j=day[1],res=1;i<=n;i++) if((j=j+day[i])>mid) { res++; j=day[i]; } if(res<m) sum=mid-1; if(res==m) sum=mid; if(res>m) max=mid+1; } printf("%d\n",max); } return 0; }
相关文章推荐
- POJ3273 Monthly Expense 二分搜索
- 二分搜索 (Binary Search)
- POJ-2503(二分搜索)
- 假定一个解并判断是否可行(二分搜索应用)
- 0003算法笔记——【分治法】分治法与二分搜索,棋盘覆盖问题
- “玲珑杯”线上赛 Round #15 咸鱼魔法记(二分搜索)
- java 二分搜索
- 每日一题7:二分搜索
- 递归方法实现二分搜索
- HDU 4004 The Frog's Games(基本算法-贪心,搜索-二分)
- POJ 2723 Get Luffy Out(图论-2SAT,搜索-二分)
- 特定字符输出及二分搜索 简单面试编程题
- POJ3273:Monthly Expense(二分)
- 二分搜索 UVALive 6076 Yukari's Birthday (12长春K)
- BZOJ 1082 栅栏 [二分+搜索]
- 正确的二分搜索代码
- 二分搜索大法
- 怎样写出一个正确的二分搜索
- 2144 砝码称重 2 用map离散化hasi+二分搜索