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

  1. Input:
  2. 2
  3. 4
  4. 1 2 4 8
  5. 4
  6. 1 3 4 5
  7.  
  8. Output:
  9. Case 1: 1
  10. Case 2: 3

n个盒子要叠起来,大小为k的盒子可以放进大小为2k的空盒子里,问最少剩多少

排个序贪心就好了,维护一个队列表示当前可以塞到其他盒子里的盒子,每次新来一个盒子的时候,把最小的那个塞进去

最后答案就是队列大小了

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<deque>
  9. #include<set>
  10. #include<map>
  11. #include<ctime>
  12. #define LL long long
  13. #define inf 0x7ffffff
  14. #define pa pair<int,int>
  15. #define mkp(a,b) make_pair(a,b)
  16. #define pi 3.1415926535897932384626433832795028841971
  17. #define mod 100007
  18. using namespace std;
  19. inline LL read()
  20. {
  21. LL x=,f=;char ch=getchar();
  22. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  23. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  24. return x*f;
  25. }
  26. int n,t,w,ans;
  27. int q[];
  28. int a[];
  29. inline void work(int cur)
  30. {
  31. n=read();
  32. for (int i=;i<=n;i++)a[i]=read();
  33. sort(a+,a+n+);
  34. t=w=ans=;
  35. for (int i=;i<=n;i++)
  36. {
  37. if (t==w)q[++w]=a[i]*,ans++;
  38. else if (q[t+]<=a[i])t++,q[++w]=a[i]*;
  39. else q[++w]=a[i]*,ans++;
  40. }
  41. printf("Case %d: %d\n",cur,ans);
  42. }
  43. int main()
  44. {
  45. int T=read(),tt=;
  46. while (T--)work(++tt);
  47. }

Spoj VISIBLEBOX

Spoj-VISIBLEBOX Decreasing Number of Visible Box的更多相关文章

  1. SPOJ: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】NUMOFPAL - Number of Palindromes(Manacher,回文树)

    [SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...

  3. Spoj MKTHNUM - K-th Number

    题目描述 English Vietnamese You are working for Macrohard company in data structures department. After f ...

  4. SPOJ - VISIBLEBOX [multiset的使用]

    tags:[STL][sort][贪心]题解:做法:先对数组a进行排序,再将数组a从头到尾扫一遍,使用multiset维护最小值,如果,即将放入集合的数字>=最小值的两倍,那我们就删除掉多重集合 ...

  5. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

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

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

  7. poj 3060 Visible Lattice Points

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

  8. P8 Visible Lattice Points

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

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

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

随机推荐

  1. Heacher互助平台 α版本冲刺

    课程属性 作业课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/ 作业链接 https://edu.cnblogs.co ...

  2. table 会有默认的外边框,内部会有分割线

    .表格中边框的显示 只显示上边框 <table frame=above> 只显示下边框 <table frame=below> 只显示左.右边框 <table frame ...

  3. 【转】CPU个数,核心数,线程数

    我们在买电脑的时候,经常会看cpu的参数,对cpu的描述有这几种:“双核”.“双核四线程”.“四核”.“四核四线程”.“四核8线程”……. 我们接触的电脑基本上都只有一个cup.cpu的个数很容易得到 ...

  4. Docker和K8S

    干货满满!10分钟看懂Docker和K8S [摘自:https://my.oschina.net/jamesview/blog/2994112]   本文来源微信号:鲜枣课堂 2010年,几个搞IT的 ...

  5. rhel7.3smb安装配置

    rhel7.3smb安装配置 1.安装 yum -y install samba samba-client cifs-utils 2.配置开机自启动,覆盖原配置文件 systemctl enable ...

  6. ios之UIScrollView

    UIScrollView 类负责所有基于 UIKit 的滚动操作. 一.创建 [java] view plaincopy     CGRect bounds = [ [ UIScreen mainSc ...

  7. Fortran学习记录3(选择语句)

    流程控制语句 if的基本用法 if-else语句块 多重判断if-elseif语句 if语句嵌套 Select case语句 Goto语句 PAUSE CONTINUE STOP 流程控制语句 if的 ...

  8. 关于PHP版本比较函数version_compare的问题

    $version1="v4.0"; $version2="v4.0.0"; print_r(version_compare($version1,$version ...

  9. PyCharm学习笔记(一) 界面配置

     通过Ctrl+鼠标滚轮调整字体大小  设置代码区默认字体及大小 设置调试区的字体大小 设置代码风格:如Tab缩进 定义Python模板文件 # @Time : ${DATE} ${TIME} # @ ...

  10. shell-code-2-传参

    #在执行shell脚本时,带参数,如./test.sh 1 2 3,则在脚本test.sh内,参数表示为$n的形式,$1为第一个参数,以此类推. echo "第一个参数为:$1"; ...