POJ 3273 Monthly Expense (二分)
来源:互联网 发布:淘宝店培训哪家比较好 编辑:程序博客网 时间:2024/06/01 07:46
题目地址:POJ 3273
水题。居然错了两次,sad、、
代码如下:
#include <iostream>#include <string.h>#include <math.h>#include <queue>#include <algorithm>#include <stdlib.h>#include <map>#include <set>#include <stdio.h>using namespace std;#define LL __int64#define pi acos(-1.0)const int mod=9901;const int INF=0x3f3f3f3f;const double eqs=1e-8;int a[110000];int main(){ int n, m, i, cnt, sum; while(scanf("%d%d",&n,&m)!=EOF) { for(i=0; i<n; i++) { scanf("%d",&a[i]); } int low=0, high=1e9, mid, ans; while(low<=high) { mid=low+high>>1; cnt=1; sum=0; for(i=0; i<n; i++) { if(a[i]>mid) { cnt=m+1; break; } if(sum+a[i]>mid) { sum=a[i]; cnt++; } else sum+=a[i]; if(cnt>m) break; } if(cnt<=m) { ans=mid; high=mid-1; } else low=mid+1; } printf("%d\n",ans); } return 0;}
1 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(二分)
- 重载与重写,继承与多态
- jsp 常用标签
- 程序集引用版本冲突问题的解决办法:合并依赖项
- linux下使用yum安装mysql
- contiki 源码分析之platform(一)(platform / cc2530dk)
- POJ 3273 Monthly Expense (二分)
- OpenCV+KMeans算法
- Xen in WiFi networks
- 双倍提升Apache Spark排序性能
- Sollin算法的C++实现 BY gremount
- 基于java config的springSecurity(六)--集成spring session
- (总结)Nginx/LVS/HAProxy负载均衡软件的优缺点详解
- iOS中NSAssert()断言的使用
- CSU 1354 Distinct Subsequences 求不同子序列和 dp