10396: H.Rectangles

Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 229  Solved: 33 [Submit][Status][Web Board]

Description

Given N (4 <= N <= 100)  rectangles and the lengths of their sides ( integers in the range 1..1,000), write a program that finds the maximum K for which there is a sequence of K of the given rectangles that can "nest", (i.e., some sequence P1, P2, ..., Pk, such that P1 can completely fit into P2, P2 can completely fit into P3, etc.).

A rectangle fits inside another rectangle if one of its sides is strictly smaller than the other rectangle's and the remaining side is no larger.  If two rectangles are identical they are considered not to fit into each other.  For example, a 2*1 rectangle fits in a 2*2 rectangle, but not in another 2*1 rectangle.

The list can be created from rectangles in any order and in either orientation.

Input

The first line of input gives a single integer, 1 ≤ T ≤10,  the number of test cases. Then follow, for each test case:

* Line 1:       a integer N ,  Given the number ofrectangles  N<=100

* Lines 2..N+1:  Each line contains two space-separated integers  X  Y,  the sides of the respective rectangle.   1<= X , Y<=5000

Output

Output for each test case , a single line with a integer  K ,  the length of the longest sequence of fitting rectangles.

Sample Input

1
4
8 14
16 28
29 12
14 8

Sample Output

2

HINT

 

Source

第七届河南省赛

题解:矩形嵌套数目,只需要把x从小到大排列,找lis就好了;注意x要比y小,lis要upper;

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
struct Node{
int x,y;
friend bool operator < (Node a,Node b){
if(a.x!=b.x)return a.x<b.x;
else return a.y<b.y;
}
};
Node d[110],dt[110];
int main(){
int T,N;
SI(T);
while(T--){
SI(N);
int x,y;
for(int i=0;i<N;i++){
scanf("%d%d",&x,&y);
d[i].x=min(x,y);d[i].y=max(x,y);
}
sort(d,d+N);
int k=1;
dt[0].x=d[0].x;dt[0].y=d[0].y;
if(N==0){
puts("0");continue;
}
for(int i=1;i<N;i++){
while(d[i].x==d[i-1].x&&d[i].y==d[i-1].y)i++;
dt[k++]=d[i];
}
/*for(int i=0;i<k;i++){
printf("%d %d\n",dt[i].x,dt[i].y);
}*/
vector<int>vec;
for(int i=0;i<k;i++){
if(upper_bound(vec.begin(),vec.end(),dt[i].y)==vec.end())
vec.push_back(dt[i].y);
else *upper_bound(vec.begin(),vec.end(),dt[i].y)=dt[i].y;
} printf("%d\n",vec.size());
}
return 0;
}

  

第七届河南省赛H.Rectangles(lis)的更多相关文章

  1. 第七届河南省赛10403: D.山区修路(dp)

    10403: D.山区修路 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 69  Solved: 23 [Submit][Status][Web Bo ...

  2. 第七届河南省赛10402: C.机器人(扩展欧几里德)

    10402: C.机器人 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 53  Solved: 19 [Submit][Status][Web Boa ...

  3. 第七届河南省赛G.Code the Tree(拓扑排序+模拟)

    G.Code the Tree Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 18 [Submit][Status][Web ...

  4. 第七届河南省赛B.海岛争霸(并差集)

    B.海岛争霸 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 130  Solved: 48 [Submit][Status][Web Board] D ...

  5. 第七届河南省赛A.物资调度(dfs)

    10401: A.物资调度 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 95  Solved: 54 [Submit][Status][Web Bo ...

  6. 第七届河南省赛F.Turing equation(模拟)

    10399: F.Turing equation Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 151  Solved: 84 [Submit][St ...

  7. 山东省第七届省赛 D题:Swiss-system tournament(归并排序)

    Description A Swiss-system tournament is a tournament which uses a non-elimination format. The first ...

  8. 山东省第六届省赛 H题:Square Number

    Description In mathematics, a square number is an integer that is the square of an integer. In other ...

  9. poj 2567 Code the Tree 河南第七届省赛

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2350   Accepted: 906 Desc ...

随机推荐

  1. nodejs 下载网页及相关资源文件

    功能其实很见简单,通过 phantomjs.exe 采集 url 加载的资源,通过子进程的方式,启动nodejs 加载所有的资源,对于css的资源,匹配css内容,下载里面的url资源 当然功能还是很 ...

  2. (译) 《Javascript 24条最佳实践》

    (摘录) <Javascript 24条最佳实践> 自己一直偏向于实用主义,不是学院派,不是学究派,只讲究把东西能够很好的做出来,但经过一段时间的开发工作当自己总结出来一些东西时,觉得挺有 ...

  3. 原版Windows XP Pro With SP3 VOL MSDN简体中文专业版

    2008年5月2日,微软推出Windows XP Pro With SP3 VOL MSDN x86 32位简体中文专业版,这是最经典也是我最喜爱的操作系统之一.在MSDN(微软开发者网络)的网站上查 ...

  4. 编程珠玑I算法总结

    主要是根据编程珠玑后面的Algorithm附录总结了一下这本书里面的经典算法. 1 辗转相减求最大公约数 思想:最大公约数能整除i和j,则其一定也能整除i-j(if i>j) int gcd(i ...

  5. poj2262---素数(质数)的判断

    收获:一开始以为是100万的所有数字,题目要求是只要偶数,也可以分析出来,如果是给一个奇数,当我们给他大于等于3的奇数(这个数加有可能不是质数,但至少满足是奇数,至于是不是质数还要自己判断),剪出来一 ...

  6. poj2105---用指针对数组分块操作

    #include <stdio.h> #include <stdlib.h> ; int pow1(int a,int b) { ,i; ) ; ;i<b;i++) { ...

  7. Java面试题之六

    三十一.如何取小数点前两位,并四舍五入. package com.lovo; public class TestDot2 { // 方法1 public void test1(double c) { ...

  8. android开发利器--站在巨人肩膀上前行

    本文主要介绍有助于android开发的三方平台和站点. 一:开发阶段 1:SVN(一个开放源码的版本号控制系统) 团队开发没有server,代码管理就没那么方便了,推荐taocode阿里开源站点,方便 ...

  9. ListView分割线

    在开发中遇到需要ListView 中每一个条目后面都有个分隔线,但是总是发现最后一个条目后面没有分隔符,后来查到原因,是因为ListView的layout_height=“wrap_content” ...

  10. Android 自动编译、打包生成apk文件 3 - 使用SDK Ant方式

      相关文章列表: < Android 自动编译.打包生成apk文件 1 - 命令行方式> < Android 自动编译.打包生成apk文件 2 - 使用原生Ant方式> &l ...