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: ...
随机推荐
- ActiveAndroid问题no such table解决总结
android.database.sqlite.SQLiteException: no such table at android.database.sqlite.SQLiteConnection ...
- IOS Array 排序方法
NSArray *sortedArray = [array sortedArrayUsingComparator: ^(id obj1, id obj2) { if ([obj1 integerVal ...
- 分布式文件系统ceph介绍
ceph哲学思想 1. 每个组件必须支持扩展 2.不存在单点故障 3.解决方案必须是基于软件的.开源的.适应能力强 4.任何可能的一切必须自我管理 存在的意义:帮助企业摆脱昂贵的专属硬件 ceph目标 ...
- excel数据导入到数据库
package test; import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundExceptio ...
- java在线聊天项目 swt可视化窗口Design 重新设计聊天窗口
设计的聊天窗口如下: 制作过程: 首先,在默认的BorderLayout视图下, 上边也就是North处添加一个JPanel,将Layout调整为BorderLayout,West放一个JLabel用 ...
- 121. Best Time to Buy and Sell Stock@python
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- nxlog安装配置
Nxlog安装配置文档 任 帅 1.安装nxlog,全部默认即可. 如果拷贝直接安装,没有拷贝可以下载.下载链接: https://nxlog.co/system/files/products ...
- Python网络爬虫(Get、Post抓取方式)
简单的抓取网页 import urllib.request url="http://google.cn/" response=urllib.request.urlopen(url) ...
- ZZULIoj 1907 小火山的宝藏收益
Description 进去宝藏后, 小火山发现宝藏有N个房间,且这n个房间通过N-1道门联通. 每一个房间都有一个价值为Ai的宝藏, 但是每一个房间也都存在一个机关.如果小火山取走了这 ...
- TSOJ--方格上的路径
题目描述: 试求 n × m 的方格图形中,从点 (0, 0) 到点 (n, m) 的最短路径数目. 输入描述: 有多组测试数据.输入的第一行为一个正整数 N,表示接下来有 N 组测试数据. 在接下来 ...