二分求箱子中的票数  然后判是否满足条件     主要为了纪念一下用优先队列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. java源码研究--List中的set和add方法区别

    在处理一道题目是,发现他们使用了List 中的set 方法,这个方法我平时很少用到,今天来研究一下,set和add的区别 add(int index,Object obj)方法与set(int ind ...

  2. 利用google api生成二维码名片例子

    二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码.堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成:矩阵式二维条码以矩阵的形式组成,在矩阵相应元素位置上用“点”表示二进制“1” ...

  3. 【转载】 c语言inline函数的使用

    c语言inline函数的使用 转载自:http://blog.chinaunix.net/uid-21843265-id-3056446.html 大学在教科书上学习过inline函数,定义为inli ...

  4. 第一篇、jQuery的使用

    1.jquery 的优势 >轻量级 >强大的选择器 >出色的DOM操作封装 >完善的事件和事件对象的兼容机制 >完善的ajax >不污染全局变量($可以随时交出控制 ...

  5. Cocos2d-x开发实例:使用Lambda 表达式

    在Cocos2d-x 3.0之后提供了对C++11标准[1]的支持,其中的Lambda[2]表达式使用起来非常简洁.我们可以使用Lambda表达式重构上一节的实例. 我们可以将下面的代码: liste ...

  6. 前端性能优化工具--DOM Monster

    当我们开发web应用的时候,性能是一个永远不能回避的问题.其实对于DOM的性能调试也是一个不可或缺的过程.使用DOM monster你只需要添加到你的”书签中“,在任何需要调试的页面点击这个书签,它就 ...

  7. JAVA解析XML的四种方式

    java解析xml文件四种方式 1.介绍 1)DOM(JAXP Crimson解析器) DOM是用与平台和语言无关的方式表示XML文档的官方W3C标准.DOM是以层次结构组织的节点或信息片断的集合.这 ...

  8. [GeekBand] C++11~14

    一.关键字decltype 由对象得到对象的数据类型,例如 Complex  a(1,  2);     decltype(a)  b(3,  4);     declare type是让编译器去找到 ...

  9. tip 2:找最小公倍数之Boost

    今天在codewars上面做了一题,kata5的,其中一个实现函数是几个数字的最小公倍数.自己的代码编译虽然也成功了,但是不够简介.看了别人的代码才发现可以直接调用Boost的math模块. 看eff ...

  10. HTML5 + SOCKET视频传输

    <html> <head> <meta http-equiv="content-type" content="text/html; char ...