poj3273
来源:互联网 发布:淘宝怎么删掉评价 编辑:程序博客网 时间:2024/05/29 04:36
链接:点击打开链接
题意:给出N个数,分成M部分(不能调换顺序),使得分成的M部分中和的最大值最小
代码:
#include <cstdio>#include <iostream>using namespace std;const int INF=0x3f3f3f3f;int N,M;int x[1000005];int judge(int d){ int i,sum,cou; sum=cou=0; for(i=0;i<N;i++){ sum+=x[i]; if(sum>d){ cou++; sum=x[i]; } } if(sum!=0) return cou+1; return cou;} //最大值是d时能分成几部分int main(){ int i,j,l,r,mid,sum,ans; while(scanf("%d%d",&N,&M)!=EOF){ l=sum=0; for(i=0;i<N;i++){ scanf("%d",&x[i]); sum+=x[i]; l=max(l,x[i]); } r=sum; while(l<=r){ //二分 最小化最大值 mid=(l+r)/2;// cout<<l<<" "<<r<<" "<<mid<<" "<<judge(mid)<<endl; if(judge(mid)<=M){ ans=mid; r=mid-1; } else l=mid+1; } printf("%d\n",ans); } return 0;}
0 0
- poj3273
- poj3273
- poj3273
- poj3273
- poj3273
- poj3273
- poj3273
- poj3273
- poj3273
- POJ3273
- poj3273
- poj3273
- poj3273
- POJ3273
- poj3273 二分
- POJ3273 二分
- 【POJ3273】二分
- poj3273解题报告
- 将输入的整数排序并指定位置逆序存放
- 设计模式之创建模式
- Linux(Centos6.5)下安装svn服务器,并通过http访问
- 如何处理Tableview中cell的单选问题
- Unity学习笔记(2) --- Unity脚本的生命周期
- poj3273
- cocos2d-x v2 和 v3 对照手册
- 设计模式之单例、多例模式
- unity 延时调用方法
- mysql命令
- python2.7.10
- 修改数据库名 -----表名 ------属性名等
- 大话设计模式_桥接模式c++实现
- ShareSDK集成登陆功能