• 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 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个盒子要叠起来,大小为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=0,f=1;char ch=getchar();
    22     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    23     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    24     return x*f;
    25 }
    26 int n,t,w,ans;
    27 int q[100010];
    28 int a[100010];
    29 inline void work(int cur)
    30 {
    31     n=read();
    32     for (int i=1;i<=n;i++)a[i]=read();
    33     sort(a+1,a+n+1);
    34     t=w=ans=0;
    35     for (int i=1;i<=n;i++)
    36     {
    37         if (t==w)q[++w]=a[i]*2,ans++;
    38         else if (q[t+1]<=a[i])t++,q[++w]=a[i]*2;
    39         else q[++w]=a[i]*2,ans++;
    40     }
    41     printf("Case %d: %d
    ",cur,ans);
    42 }
    43 int main()
    44 {
    45     int T=read(),tt=0;
    46     while (T--)work(++tt);
    47 }
    Spoj VISIBLEBOX
  • 相关阅读:
    hdu 1086 You can Solve a Geometry Problem too 求n条直线交点的个数
    2019 上半年 南昌网络赛
    第十章 存储过程和函数
    第九章 Mysql函数
    第八章 Mysql运算符
    第七章 插入、更新与删除数据
    第六章 查询数据
    第五章 触发器
    第四章 视图
    第三章 索引
  • 原文地址:https://www.cnblogs.com/zhber/p/7153384.html
Copyright © 2020-2023  润新知