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. GIL锁、死锁、递归锁、定时器

    GIL (Global Interpreter Lock) 锁 '''定义:In CPython, the global interpreter lock, or GIL, is a mutex th ...

  2. (44)C#网络2

    一.用SmtpClient类发送邮件 允许应用程序使用简单邮件传输协议 (SMTP) 发送电子邮件 using System.Net.Mail; SmtpClient smtpClient = new ...

  3. (12)java -IDEA使用

    一. 引入jar包 1. 2.

  4. Bruce Eckel:编程生涯

    大家总是问一个错误的问题:“我应该学习C++还是Java?”在本文中,我将告诉大伙儿:对于选择编程生涯真正需要关注的是哪些问题. 请注意,这篇文章的目标读者并不是那些已经做出自己选择的人.(对于这些人 ...

  5. Codeforces 961 E Tufurama

    Discription One day Polycarp decided to rewatch his absolute favourite episode of well-known TV seri ...

  6. NSTimer与NSRunLoop的关系分析

    NSTimer与NSRunLoop的关系分析 发表于 2013 年 6 月 27 日 由 bluev | 6 次浏览 最近关于NSTimer和NSRunLoop的关系,做了一个小试验.代码地址:htt ...

  7. 【转】Linux cp -a用法

    cp file1 file1-bk  ---------> 这样复制备份的话文件的属性(创建时间这些会变化) 要想不变化, cp -a  file1 file-bk  加上一个 -a 这个参数就 ...

  8. TraceTool 跟踪工具的瑞士军刀(C++版使用)

    TraceTool查看器能够显示多种类型的来源(从提供的框架.日志文件.事件日志.或者OutputDebugString方法).一个简单而强大的client框架发送简单的跟踪,分组跟踪.类和对象浏览器 ...

  9. js 验证 输入值 全是数字

    1.使用isNaN()函数 isNaN()的缺点就在于 null.空格以及空串会被按照0来处理 NaN: Not a Number /** *判断是否是数字 **/ function isRealNu ...

  10. HDU 1060 Leftmost Digit (数学/大数)

    Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...