Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman wants to hide boxes as many as possible. A box can be kept hidden inside of another box if and only if the box in which it will be held is empty and the size of the box is at least twice as large as the size of the box.

Print the minimum number of box that can be shown.

Input

The input set starts with single line integer T (1<=T<=50) the number of test cases. Then following T cases starts with an integer N (1<=N<=100000) denoting the number of box. The next line contains N space separated positive integer. i-th of them contains a numbers Ai(1<=Ai<=100000) size of the i-th box.

Output

Output the the case number and the minimum number of box that can be shown.

Example

Input:
2
4
1 2 4 8
4
1 3 4 5 Output:
Case 1: 1
Case 2: 3

题意:给定N个盒子,现在每个盒子最多可以装一个盒子到内部,而且要满足外面的盒子体积大于等于内部的盒子的两倍。

思路:开始以为是平衡树,每次在树上找到一个大于等于两倍体积的点,减减。但是复杂度太高,优化看一下也超时。最后又是手欠看了别人的代码。

方法大概是,先排序,然后新建一个数组q,代表目前最小的盒子的两倍,如果后面的盒子大于这个q,就可以把q装进去,装一次代表答案减一。

(主要是利用了单调性,贪心地装目前最小的,秒啊。

#include<bits/stdc++.h>
using namespace std;
const int maxn=;
int a[maxn],q[maxn],head,tail;
int main()
{
int T,N,i,j,ans,Case=;
scanf("%d",&T);
while(T--){
head=tail=ans=;
scanf("%d",&N);
for(i=;i<=N;i++) scanf("%d",&a[i]);
sort(a+,a+N+);
for(i=;i<=N;i++){
if(head==tail) ans++;
else if(q[tail+]<=a[i]) tail++;
else ans++;
q[++head]=a[i]*;
}
printf("Case %d: %d\n",++Case,ans);
}
return ;
}

SPOJ:Decreasing Number of Visible Box(不错的,背包?贪心?)的更多相关文章

  1. Spoj-VISIBLEBOX Decreasing Number of Visible Box

    Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman ...

  2. SPOJ:Strange Waca(不错的搜索&贪心&剪枝)

    Waca loves maths,.. a lot. He always think that 1 is an unique number. After playing in hours, Waca ...

  3. 452. Minimum Number of Arrows to Burst Balloons——排序+贪心算法

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  4. SPOJ Find the max XOR value(二进制,贪心即可)

    You have two integers L and R, and you are required to find the max xor value of a and b where L < ...

  5. 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: ...

  6. poj 3060 Visible Lattice Points

    http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Tota ...

  7. P8 Visible Lattice Points

    P8 Visible Lattice Points Time Limit:1000ms,     Memory Limit:65536KB Description A lattice point (x ...

  8. 【POJ】3090 Visible Lattice Points(欧拉函数)

    Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7705   Accepted: ...

  9. POJ_3090 Visible Lattice Points 【欧拉函数 + 递推】

    一.题目 A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), ...

随机推荐

  1. golang测试框架--smartystreets/goconvey

    视频教程和配套博客:goconvey - 课时 1:优雅的单元测试 Go 语言虽然自带单元测试功能,在 GoConvey 诞生之前也出现了许多第三方辅助库.但没有一个辅助库能够像 GoConvey 这 ...

  2. 使用systemtap调试Linux内核 :www.lenky.info

    http://www.lenky.info/archives/category/nix%E6%8A%80%E6%9C%AF/%E8%B7%9F%E8%B8%AA%E8%B0%83%E8%AF%95

  3. ganglia-monitoring-centos-linux

    http://www.tecmint.com/install-configure-ganglia-monitoring-centos-linux/ http://monitor.gitlab.net/ ...

  4. docker 配置 direct-lvm

    当前需要设置的宿主机是环境是搭建在vbox虚拟机上的centos7系统.测试环境中出现过一次意外情况,当时为了测试docker日志文件限制,运行了一个docker容器,但是后面忘记停止了,几天后发现了 ...

  5. BUPT复试专题—Python List(2014)

    题目描述 在Python中,List (列表)是一种非常重要的数据结构.它与C/C++/Java中的 数组有些类似,但支持添加新元素时的动态扩展.在这个问题中,你需要处理如下 的几种对List的操作. ...

  6. BUPT 2012复试机考 2T

    题目描述 ​给你一个n*n的矩阵, , 求其矩阵的k次幂,即Pk 输入格式 第一行,一个整数T(0<T<=10),表示要求矩阵的个数. 接下来有T组数据,每组数据格式如下: 第一行:两个数 ...

  7. Django简易安装

    Django简易安装 1,下载 https://www.djangoproject.com/download/ 2, 拷贝至python同级目录 python setup.py install 3,在 ...

  8. 从机器码理解RIP 相对寻址

    本作品采用知识共享署名 4.0 国际许可协议进行许可.转载联系作者并保留声明头部与原文链接https://luzeshu.com/blog/rip-relative-addressing 本博客同步在 ...

  9. tabhost实现android菜单切换

    做APP项目已经有半个月了.慢慢地熟悉了这个开发环境和开发套路. 虽然是摸着石头过河.但也渐渐看到了水的深度! 作为一个电商项目APP,势必会涉及究竟部菜单条的功能.自己实现这个功能的过程是崎岖的,最 ...

  10. JAVA WEB学习笔记(一):JDK的安装及环境变量的配置

    一.JDK的安装. JDK可以在Oracle(甲骨文)的官网下载,连接地址:http://www.oracle.com/technetwork/java/javase/downloads/index- ...