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. fmt 包中的函数和方法

    / Fprintf 将参数列表 a 填写到格式字符串 format 的占位符中// 并将填写后的结果写入 w 中,返回写入的字节数func Fprintf(w io.Writer, format st ...

  2. SGU112

    题意:求a^b-b^a次,100以内.大数的-和*的模拟,用的模板,注意该模板中间和结果都不能出现负数. #include<iostream> #include<string> ...

  3. VMware虚拟机下安装hadoop1.x

    这是Hadoop学习全程记录第1篇,在这篇里我将介绍一下如何在Linux下安装Hadoop1.x. 先说明一下我的开发环境: 虚拟机:VMware8.0: 操作系统:CentOS6.4: 版本:jdk ...

  4. Nginx阻止DDoS攻击的教程收集(转)(待实践)

    DDoS估计是一个非常头痛的问题. 分布式拒绝服务攻击(DDoS)指的是通过多台机器向一个服务或者网站发送大量看似合法的数据包使其网络阻塞.资源耗尽从而不能为正常用户提供正常服务的攻击手段.随着互联网 ...

  5. easyui combobox模糊查询

    用easyui框架开发的攻城狮恐怕都遇到过这样一个问题,就是在新增页面combobox下拉框需要支持模糊查询,但是输入不是combobox中Data里面的值的时候,点击保存,依然是可以新增进去的,这样 ...

  6. java cocurrent并发包

    1. java.util.concurrent - Java 并发工具包Java 5 添加了一个新的包到 Java 平台,java.util.concurrent 包.这个包包含有一系列能够让 Jav ...

  7. 【hibernate/JPA】注解方式实现 复合主键【spring boot】

    1>hibernate/JPA实现复合主键的思路:是将所有的主键属性封装在一个主键类中,提供给需要复合主键的实体类使用. 2>主键类的几点要求: . 使用复合主键的实体类必须实现Seria ...

  8. 空暇时候思考2(&#39;\0&#39;等价于数字0还是字符0)

    /********************************************************************** * * Copyright (c)2015,WK Stu ...

  9. 转:一个android开发者独立开发社交app全过程

    http://www.cnblogs.com/linguanh/p/5683069.html

  10. Loadrunner IP欺骗

    一.为什么要设置IP欺骗 1. 当某个IP的訪问过于频繁,或者訪问量过大时,server会拒绝訪问请求.这时候通过IP欺骗能够添加訪问频率和訪问量,以达到压力測试的效果. 2. 某些server配置了 ...