/**
题目:2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower
链接:http://codeforces.com/gym/101194
题意:给n个木块,堆一个小塔要k个木块,满足相邻两个木块,上面的木块大小至少是下面的木块的两倍。
问最多可以堆出几个小塔。 思路:二分+贪心。 先二分最终可以堆出的小塔数x,然后确定了数量,就可以这样来贪心,把前x个木块作为所有小塔的顶部木块,
然后从剩下的木块中继续取前x小的,从小到大放在x个小塔的次顶部,然后继续。。。如果可以取到k层。那么该方案有解。找一个最大的二分结果即可。 */ #include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;
typedef pair<int,int> P;
typedef __int64 LL;
const int N = 3e5+;
const int mod = 1e9+;
const int INF = 0x3f3f3f3f;
LL b[N], a[N];
int n, k;
bool ok(int x)
{
for(int i = ; i < x; i++){
a[i] = b[i];
}
int as, bs;
as = bs = x;
for(int i = ; i <= (k-)*x; i++){
while(bs<n&&b[bs]<*a[as-x]){bs++;}
if(bs==n) return false;
a[as++] = b[bs++];
}
return true;
}
int solve()
{
int lo = , hi = n/k, mi;
int ans;
while(lo<=hi){
mi = (lo+hi)/;
if(ok(mi)){
//cout<<"mi = "<<mi<<endl;
ans = mi;
lo = mi+;
}else
{
hi = mi-;
}
}
return ans;
}
int main(void)
{
int T;
int cas = ;
cin>>T;
while(T--)
{
scanf("%d%d",&n,&k);
for(int i = ; i < n; i++){
scanf("%I64d",&b[i]);
}
sort(b,b+n);
printf("Case #%d: %d\n",cas++,solve());
}
return ;
}

2016-2017 ACM-ICPC CHINA-Final Ice Cream Tower 二分+贪心的更多相关文章

  1. The 2016 ACM-ICPC Asia China-Final D. Ice Cream Tower 二分 + 贪心

    题目大意: 对于给出的n个冰激凌球的大小,满足下面的球的大小是上一个的至少2倍,对于给出的k(由k的冰激凌球才能算作一个冰激凌塔),问n个冰激凌球可以最多堆出多少个高度为k的冰激凌塔 题目分析: 对于 ...

  2. Gym 101194D / UVALive 7900 - Ice Cream Tower - [二分+贪心][2016 EC-Final Problem D]

    题目链接: http://codeforces.com/gym/101194/attachments https://icpcarchive.ecs.baylor.edu/index.php?opti ...

  3. ACM ICPC China final G Pandaria

    目录 ACM ICPC China final G Pandaria ACM ICPC China final G Pandaria 题意:给一张\(n\)个点\(m\)条边的无向图,\(c[i]\) ...

  4. 2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  5. 2017 ACM/ICPC Shenyang Online SPFA+无向图最长路

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  6. 2017 ACM ICPC Asia Regional - Daejeon

    2017 ACM ICPC Asia Regional - Daejeon Problem A Broadcast Stations 题目描述:给出一棵树,每一个点有一个辐射距离\(p_i\)(待确定 ...

  7. 2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest

    2017 ACM - ICPC Asia Ho Chi Minh City Regional Contest A - Arranging Wine 题目描述:有\(R\)个红箱和\(W\)个白箱,将这 ...

  8. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  9. Ice Cream Tower(The 2016 ACM-ICPC Asia China-Final Contest 二分&贪心)

    题目: Mr. Panda likes ice cream very much especially the ice cream tower. An ice cream tower consists ...

随机推荐

  1. 隐藏系统EFI分区Z盘

    找到C:\Windows\System32\cmd.exe程序, 右键单击cmd 选择以管理员身份运行, 打开命令提示符,输入以下命令(不区分大小写)DiskPart回车List空格volume回车s ...

  2. hdu1800Flying to the Mars (字典树)

    Problem Description In the year 8888, the Earth is ruled by the PPF Empire . As the population growi ...

  3. ffmpeg代码解析

    void avdevice_register_all(void){    static int initialized;    if (initialized)        return;    i ...

  4. Shell 基本运算符(转)

    Shell 和其他编程语言一样,支持多种运算符,包括: 算数运算符 关系运算符 布尔运算符 字符串运算符 文件测试运算符 原生bash不支持简单的数学运算,但是可以通过其他命令来实现,例如 awk 和 ...

  5. c++11 Using Callable Objects, std::thread, std::bind, std::async, std::call_once

  6. python能够执行,但编译第三包遇到 python.h no such file or directory

    python能够执行,但编译第三包遇到 python.h no such file or directory 这个问题是由于没有安装python-devel, 安装此包就能够解决次问题,在Linux下 ...

  7. ECMAScript6 | 新特性(部分)

    新特性概览 参考文章:http://www.cnblogs.com/Wayou/p/es6_new_features.html 这位前辈写的很好,建议深入学习 ———————————————————— ...

  8. iTunes 无法添加 iPhone 自定义铃声

    本篇文章由:http://xinpure.com/itunes-unable-to-add-iphone-custom-ringtones/ 新版本 iTunes 需要在 菜单栏 -> 文件 中 ...

  9. html5_storage存取实例

    <script src="jquery-1.8.3.js"></script><script>function set(){    var tt ...

  10. SSH整合简单例子

    说明:简单SSH整合,struts版本2.3.32,spring版本3.2.9,hibernate版本3.6.10 一.开发步骤 1 引jar包,创建用户library.使用的包和之前博文相同,可以参 ...