二分求箱子中的票数  然后判是否满足条件     主要为了纪念一下用优先队列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的更多相关文章

  1. hdu 4190 Distributing Ballot Boxes(贪心+二分查找)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4190 Distributing Ballot Boxes Time Limit: 20000/1000 ...

  2. hdu 4190 Distributing Ballot Boxes 二分

    Distributing Ballot Boxes Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  3. HDU 4190 Distributing Ballot Boxes【二分答案】

    题意:给出n个城市,n个城市分别的居民,m个盒子,为了让每个人都投上票,问每个盒子应该装多少张票 二分盒子装的票数, 如果mid<=m,说明偏大了,r应该向下逼近 ,r=mid 如果mid> ...

  4. hdu 4193 Non-negative Partial Sums 单调队列。

    Non-negative Partial Sums Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. Android中android-async-http开源网络框架的简单使用

    android-async-http开源网络框架是专门针对Android在Apache的基础上构建的异步且基于回调的http client.所有的请求全在UI线程之外发生,而callback发生在创建 ...

  2. Javascript之获取屏幕宽高

    <head> <title> new document </title> <meta name="generator" content=& ...

  3. SQL通过日期计算年龄

    首先建立一个表如下: ======================= BirthDay datetime not null Age 通过公式计算得出 ======================= 以 ...

  4. switch的case中不能做定义

    switch的case中不能做定义 只能给语句 error: a label can only be part of a statement and a declaration is not a st ...

  5. Poj 3062 Celebrity jeopardy

    1.Link: http://poj.org/problem?id=3062 2.Content: Celebrity jeopardy Time Limit: 1000MS   Memory Lim ...

  6. 分布式之高性能IO组件

    因为毕业设计(实时分析大型数据流),开始对分布式并行计算做研究,第一个问题就是通讯.高性能的通讯是整个系统性能的基本保障. 方案 就目前的经验来讲,最好的通信选择是:异步非阻塞IO + 资源池. 异步 ...

  7. 分享一个难得的YiBo微博客户端应用源码Android版

    今天给大家分享一款,YiBo微博客户端应用源码,这是一款专为Android用户打造的聚合型微博客户端,完美支持新浪微博.腾讯微博.搜狐微博.网易微博和饭否五个微博平台,界面清爽,使用简单轻巧,支持多账 ...

  8. [原创] linux课堂-学习笔记-课程3.Linux目录结构介绍及内核与shell分析

    一.目录说明 1.1 bin 一般用户,可执行的系统内置命令 1.2 sbin 系统管理员,可执行的系统内置命令 1.3 boot 启动文件目录,启动有关的文件都保存在此 1.4 dev 设备管理文件 ...

  9. js中的异常处理try...catch使用介绍

    在JavaScript可以使用try...catch来进行异常处理. 例如: try { foo.bar();} catch (e) { alert(e.name + ": " + ...

  10. ubuntu14.04 中文输入法无法使用

    说下我的解决方法吧,我是忘了在All Settings -> Text Entry 的 Input sources to use中添加Chinese(Pinyin)了,添加后就好了. from: ...