hdu 4190
二分求箱子中的票数 然后判是否满足条件 主要为了纪念一下用优先队列9000ms水过
#include<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
int n,m,a[600000];
bool check(int mid)
{
int cnt = 0;
for(int i = 0; i < n; i++)
cnt += a[i]/mid+(a[i]%mid>0);
return cnt <= m;
}
int solve(int x,int y)
{
if(x == y) return x;
int mid = x+(y-x)/2;
if(check(mid))
return solve(x, mid);
else
return solve(mid+1, y);
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF && ((n+1)||(m+1)))
{
int big = 0;
int small = INT_MAX;
for(int i = 0; i < n; i++)
scanf("%d",&a[i]),big=max(a[i],big),small=min(a[i],small);
sort(a,a+n);
printf("%d\n",solve(1,big));
}
return 0;
}
#include <iostream>
#include <cmath>
#include <fstream>
#include <cstring>
#include <queue>
using namespace std;
struct node
{
int a,b;
node(int i, int j)
{
a = i, b = j;
}
bool operator < (const node &p) const
{
return ((double)a/b) < ((double)p.a/p.b);
}
}; int main()
{
//freopen("in.txt","r",stdin);
int n,k;
while(scanf("%d%d",&n,&k) == 2)
{
if(n == -1 && k == -1)
break;
k -= n;
priority_queue<node> Q;
for(int i = 0; i < n; i++)
{
int x;
scanf("%d",&x);
Q.push(node(x, 1));
}
// cout<<Q.top().a<<endl;
while(k--)
{
node u = Q.top();
Q.pop();
Q.push(node(u.a, u.b+1));
}
printf("%d\n",(int)ceil((double)Q.top().a/Q.top().b));
}
return 0;
}
hdu 4190的更多相关文章
- hdu 4190 Distributing Ballot Boxes(贪心+二分查找)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...
- hdu 4190 Distributing Ballot Boxes 二分
Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- HDU 4190 Distributing Ballot Boxes【二分答案】
题意:给出n个城市,n个城市分别的居民,m个盒子,为了让每个人都投上票,问每个盒子应该装多少张票 二分盒子装的票数, 如果mid<=m,说明偏大了,r应该向下逼近 ,r=mid 如果mid> ...
- hdu 4193 Non-negative Partial Sums 单调队列。
Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
- hdu 4859 海岸线 Bestcoder Round 1
http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...
- HDU 4569 Special equations(取模)
Special equations Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 4006The kth great number(K大数 +小顶堆)
The kth great number Time Limit:1000MS Memory Limit:65768KB 64bit IO Format:%I64d & %I64 ...
随机推荐
- contentProvider-联系人的CURD
1.联系人的查找 返回一个ArrayList<HashMap<String, String>>类型 //通过管理联系人的URI获取游标对象 Cursor cursor= ge ...
- <转载>批处理之FOR语句祥解
批处理之FOR语句祥解 FOR这条命令基本上都被用来处理文本,但还有其他一些好用的功能! 看看他的基本格式(这里我引用的是批处理中的格式,直接在命令行只需要一个%号) FOR 参数 %%变量名 IN ...
- Swing圆角边框的实现
Swing圆角边框的实现方法: package com.justplay.basic; import java.awt.Color; import java.awt.Component; import ...
- 企业SAAS的春天,将以手机应用的形式,即将到来
派尔科技吴春福 *本文是派尔为什么要投身企业移动应用的内部分享文章: *我没有仔细核查资料,仅代表个人看法,思路也是在整理过程,逻辑未必很完整,看官将就着看. 企业SAAS,概念起源是N年前,先行者也 ...
- sql语句聚合等疑难问题收集
------------------------------------------------------------------------------------ 除法运算 select 500 ...
- lex&yacc6 ---error
类的检测 http://blog.csdn.net/pandaxcl/article/details/1536784
- 关联 Android 源代码 到 Ecplise
1. 下载android 源码存于本地硬盘; 2. 打开Eclpise, 新建Android Project; 3. 在MainActivity文件中,按住Ctrl 点击Activity类 4. 弹出 ...
- 【原】EF简单使用
/// <summary> /// 数据上下文对象 /// </summary> static TestEntities te = new TestEntities(); st ...
- Websocket协议之php实现
前面学习了HTML5中websocket的握手协议.打开和关闭连接等基础内容,最近用php实现了与浏览器websocket的双向通信.在学习概念的时候觉得看懂了的内容,真正在实践过程中还是会遇到各种问 ...
- Spark小课堂Week6 启动日志详解
Spark小课堂Week6 启动日志详解 作为分布式系统,Spark程序是非常难以使用传统方法来进行调试的,所以我们主要的武器是日志,今天会对启动日志进行一下详解. 日志详解 今天主要遍历下Strea ...