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 ...
随机推荐
- 远程连接MySql连不上1130
mysql数据库user表中已存在主机=%的用户root,连接却提示1130. 用navicat开启user表>>>>在表里直接修改%账户root的密码(看到是未加密过的内容) ...
- sql 截取两个字符串之间的字符
select SUBSTRING(templatepath,CHARINDEX('/',templatepath)+1,CHARINDEX('.', templatepath)-CHARINDEX(' ...
- 大数据技术 —— MapReduce 简介
本文为senlie原创,转载请保留此地址:http://www.cnblogs.com/senlie/ 1.概要很多计算在概念上很直观,但由于输入数据很大,为了能在合理的时间内完成,这些计算必须分布在 ...
- 第六十六篇、OC_Sqlite数据库操作
#import <Foundation/Foundation.h> #import <sqlite3.h> #define kFilename @"data.sqli ...
- Swift调用Objective-C
Swift调用Objective-C需要一个名为“<工程名>-Bridging-Header.h”的桥接头文件,如下图所示.桥接头文件的作用是为Swift调用Objective-C对象搭建 ...
- FastSocket学习笔记~制定自已的传输协议
对于TCP或者UDP来说,它们作于传输层的协议,有着自己的标准,或者叫格式,在我们看TCP格式之前先了解一下计算机的基础知识,字节,它是计算机世界的一个小单位,也是我们可以理会到的,如一个utf-8英 ...
- 深入理解JavaScript中的this关键字
1. 一般用处 2. this.x 与 apply().call() 3. 无意义(诡异)的this用处 4. 事件监听函数中的this 5. 总结 在JavaScript中this变量是一个令人难以 ...
- StringBuilder和StringBuffer
StringBuilder java.lang 类 StringBuilder java.lang.Object java.lang.StringBuilder 所有已实现的接口: Serializa ...
- What is a First Chance Exception?
Refrences: http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.aspx To be continued...
- iOS 非ARC基本内存管理系列 2-多对象内存管理(2)
/* 多对象内存管理: 以人拥有车为例涉及到@property底层set方法管理内存的实现 注意:人在换车的时候要进行当前传入的车和人所拥有的车进行判断 */ /******************* ...