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的空盒子里,问最少剩多少
排个序贪心就好了,维护一个队列表示当前可以塞到其他盒子里的盒子,每次新来一个盒子的时候,把最小的那个塞进去
最后答案就是队列大小了
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 100007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,t,w,ans;
int q[];
int a[];
inline void work(int cur)
{
n=read();
for (int i=;i<=n;i++)a[i]=read();
sort(a+,a+n+);
t=w=ans=;
for (int i=;i<=n;i++)
{
if (t==w)q[++w]=a[i]*,ans++;
else if (q[t+]<=a[i])t++,q[++w]=a[i]*;
else q[++w]=a[i]*,ans++;
}
printf("Case %d: %d\n",cur,ans);
}
int main()
{
int T=read(),tt=;
while (T--)work(++tt);
}
Spoj VISIBLEBOX
Spoj-VISIBLEBOX Decreasing Number of Visible Box的更多相关文章
- SPOJ:Decreasing Number of Visible Box(不错的,背包?贪心?)
Shadowman loves to collect box but his roommates woogieman and itman don't like box and so shadowman ...
- 【SPOJ】NUMOFPAL - Number of Palindromes(Manacher,回文树)
[SPOJ]NUMOFPAL - Number of Palindromes(Manacher,回文树) 题面 洛谷 求一个串中包含几个回文串 题解 Manacher傻逼题 只是用回文树写写而已.. ...
- Spoj MKTHNUM - K-th Number
题目描述 English Vietnamese You are working for Macrohard company in data structures department. After f ...
- SPOJ - VISIBLEBOX [multiset的使用]
tags:[STL][sort][贪心]题解:做法:先对数组a进行排序,再将数组a从头到尾扫一遍,使用multiset维护最小值,如果,即将放入集合的数字>=最小值的两倍,那我们就删除掉多重集合 ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- 数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5636 Accepted: ...
- poj 3060 Visible Lattice Points
http://poj.org/problem?id=3090 Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Tota ...
- P8 Visible Lattice Points
P8 Visible Lattice Points Time Limit:1000ms, Memory Limit:65536KB Description A lattice point (x ...
- 【POJ】3090 Visible Lattice Points(欧拉函数)
Visible Lattice Points Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7705 Accepted: ...
随机推荐
- Exoplanet: The hunt is on
原文 How many planets are out there? Today scientists believe that planets could outnumber the stars.F ...
- 适用于iOS7 UI的外描边图标素材下载
我们知道ios7的界面设计是非常简约的,图标也不例外,iOS7的icon大部使用了扁平化的外描边风格设计,使得整体看起来十分简约.耐看,这次分享达人为大家收集将近600个漂亮的外描边图标下载,这些图标 ...
- python基础面试题整理---从零开始 每天十题(03)
一.Q:用Python输出一个Fibonacci数列?(斐波那契额数列) A:我们先来看下代码 #!/usr/bin/env python # -*- coding: utf-8 -*- def fi ...
- Python3 try-except、raise和assert解析
Python3 try-except.raise和assert解析 一.说明 关于异常捕获try-except:在学java的时候就被教育异常捕获也是java相对c的一大优点,几年下来多少也写了些代码 ...
- iOS Crash
常见原因及解决方法: 1. 访问数组类对象越界或插入了空对象NSMutableArray/NSMutableDictionary/NSMutableSet 等类下标越界,或者 insert 了一个 n ...
- iOS 设计模式
很赞的总结 iOS Design Patterns 中文版 IOS设计模式之一(MVC模式,单例模式) IOS设计模式之二(门面模式,装饰器模式) IOS设计模式之三(适配器模式,观察者模式) IOS ...
- 科普NDIS封包过滤
闲言: 这个月一直在学习NDIS驱动编程,杂七杂八的资料都看个遍了,做了点笔记,捋捋思路,发上来备忘. Ps:只是小菜的一点学习笔记,没什么技术含量,不过版主如果觉得对大家稍微有点帮助的话 ...
- iOS开源库
项目告一段落,总结一下最近学习到的优秀的三方库,希望能帮到别人. (一)网络中常用的 1.网络库:AFNetworking 2.图片缓存:SDWebImage 3.网络监测 Reachability ...
- Mac 电源管理
在安装BatteryManager后,可以删除NullPowerMananger,AppleIntelPowerMananger, AppleIntelPowerClientMananger三个kex ...
- 【css】报错,错误代码77,CURLE_SSL_CACERT_BADFILE (77)解决方法
CURLE_SSL_CACERT_BADFILE (77) - 读取 SSL CA 证书时遇到问题(可能是路径错误或访问权限问题) 在微信接口相关开发时容易出现此问题 这一般是因为服务更新了相关的软件 ...