poj 3636
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8630 | Accepted: 2367 |
Description
Dilworth is the world's most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls of different sizes of which the smallest doll is contained in the second smallest, and this doll is in turn contained in the next one and so forth. One day he wonders if there is another way of nesting them so he will end up with fewer nested dolls? After all, that would make his collection even more magnificent! He unpacks each nested doll and measures the width and height of each contained doll. A doll with width w1 and height h1 will fit in another doll of width w2 and height h= if and only if w1 < w2 and h1 < h2. Can you help him calculate the smallest number of nested dolls possible to assemble from his massive list of measurements?
Input
On the first line of input is a single positive integer 1 ≤ t ≤ 20 specifying the number of test cases to follow. Each test case begins with a positive integer 1 ≤ m ≤ 20000 on a line of itself telling the number of dolls in the test case. Next follow 2m positive integers w1, h1,w2, h2, ... ,wm, hm, where wi is the width and hi is the height of doll number i. 1 ≤ wi, hi ≤ 10000 for all i.
Output
For each test case there should be one line of output containing the minimum number of nested dolls possible.
Sample Input
4
3
20 30 40 50 30 40
4
20 30 10 10 30 20 40 50
3
10 30 20 20 30 10
4
10 10 20 30 40 50 39 51
Sample Output
1
2
3
2
Source
不是很懂这个排序
上题是最长严格递减子序列,这题是最长不上升子序列
#include<cstdio>
#include<iostream>
#include<algorithm> #define N 20001 using namespace std; struct node
{
int a,b;
}e[N]; int s,f[N]; bool cmp(node p,node q)
{
if(p.a!=q.a) return p.a<q.a;
return p.b>q.b;
} int find(int w)
{
int l=,r=s,mid,tmp=-;
while(l<=r)
{
mid=l+r>>;
if(f[mid]<w) tmp=mid,r=mid-;
else l=mid+;
}
return tmp;
} int main()
{
int T,n,pos;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d%d",&e[i].a,&e[i].b);
sort(e+,e+n+,cmp);
f[s=]=2e9;
for(int i=;i<=n;i++)
if(e[i].b<=f[s]) f[++s]=e[i].b;
else
{
pos=find(e[i].b);
if(pos>) f[pos]=e[i].b;
}
printf("%d\n",s);
}
}
poj 3636的更多相关文章
- 物联网学生科协第三届H-star现场编程比赛
问题 A: 剪纸片 时间限制: 1 Sec 内存限制: 128 MB 题目描写叙述 这是一道简单的题目,假如你身边有一张纸.一把剪刀.在H-star的比赛现场,你会这么做: 1. 将这张纸剪成两片(平 ...
- POJ 3370. Halloween treats 抽屉原理 / 鸽巢原理
Halloween treats Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7644 Accepted: 2798 ...
- POJ 2356. Find a multiple 抽屉原理 / 鸽巢原理
Find a multiple Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7192 Accepted: 3138 ...
- POJ 2965. The Pilots Brothers' refrigerator 枚举or爆搜or分治
The Pilots Brothers' refrigerator Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22286 ...
- POJ 1753. Flip Game 枚举or爆搜+位压缩,或者高斯消元法
Flip Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37427 Accepted: 16288 Descr ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2255. Tree Recovery
Tree Recovery Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11939 Accepted: 7493 De ...
- POJ 2752 Seek the Name, Seek the Fame [kmp]
Seek the Name, Seek the Fame Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17898 Ac ...
随机推荐
- MacOS下搭建python环境
1. 安装须知 Mac OS自身其实已经带有Python,版本为2.7.X,这个Python主要用于支持系统文件和XCode,所以我们在安装新的Python版本时候最好不要影响这部分. 这里就会出现一 ...
- Swing State: Consistent Updates for Stateful and Programmable Data Planes
Swing State: Consistent Updates for Stateful and Programmable Data Planes 年份:2017 来源:ACM 本篇论文解决的问题 B ...
- 第二次c艹作业
1,c语言实现方法:按照电梯运行方式,改变被定义为全局变量的结构体的数值. c艹实现方法:用类来存放电梯的属性,整个过程都是对类操作. 两者不同:c语言是面向过程的,整个函数里都要对电梯的参数进行修改 ...
- lintcode-418-整数转罗马数字
418-整数转罗马数字 给定一个整数,将其转换成罗马数字. 返回的结果要求在1-3999的范围内. 说明 什么是 罗马数字? https://en.wikipedia.org/wiki/Roman_n ...
- 关于Filter的一点误解
之前一直以为请求达到Web应用时,经过过滤器1,过滤器2……,处理后产生响应再经过过滤器n……过滤器2,过滤器1.这样的阐述似乎没有问题,但我的理解却有问题.比如过滤器1的doFilter方法执行了一 ...
- erlang随机排列数组
参考karl's answer 1> L = lists:seq(1,10). [1,2,3,4,5,6,7,8,9,10] Associate a random number R with e ...
- 技嘉主板+AMD CPU开启CPU虚拟化方法
硬件环境:技嘉AB350+AMD Ryzen 5 1600X 由于安装虚拟机的需要,所以要开启CPU的虚拟化. 首先进入BIOS. 然后如图:(M.I.T-高级频率设定-CPU超频进阶设置-SVM M ...
- 控件属性和InitializeComponent()关系:
namespace Test22 { partial class Form1 { /// <summary> /// 必需的设计器变量. /// </summary> priv ...
- 自动化生成html报告
package Utils; import java.io.File; import java.util.Date; import org.apache.commons.lang3.time.Date ...
- P3629 [APIO2010]巡逻
题目描述 在一个地区中有 n 个村庄,编号为 1, 2, ..., n.有 n – 1 条道路连接着这些村 庄,每条道路刚好连接两个村庄,从任何一个村庄,都可以通过这些道路到达其 他任一个村庄.每条道 ...