第七届河南省赛H.Rectangles(lis)

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;
}

  

时间: 2024-08-07 18:25:36

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

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

B.海岛争霸 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 130  Solved: 48 [Submit][Status][Web Board] Description 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的战船黑珍珠1号要征服各个海岛的海盜,最后成为海盗王. 这是一个由海洋.岛屿和海盗组成的危险世界.杰克船长准备从自己所占领的岛屿A开始征程,逐个去占领每一个岛屿.面对危

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

10401: A.物资调度 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 95  Solved: 54 [Submit][Status][Web Board] Description 某地区发生了地震,灾区已经非常困难,灾民急需一些帐篷.衣物.食品和血浆等物资.可通往灾区的道路到处都是塌方,70%以上的路面损坏,桥梁全部被毁.国家立即启动应急预案,展开史上最大强度非作战空运行动,准备向灾区空投急需物资. 一方有难,八方支援.现在已知有N个地方分别

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

10403: D.山区修路 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 69  Solved: 23 [Submit][Status][Web Board] Description 某山区的孩子们上学必须经过一条凹凸不平的土路,每当下雨天,孩子们非常艰难.现在村里走出来的Dr. Kong决定募捐资金重新修建着条路.由于资金有限,为了降低成本,对修好后的路面高度只能做到单调上升或单调下降. 为了便于修路,我们将整个土路分成了N段,每段路面的高度分

第七届河南省赛 题解&amp;&amp;题型分布

第七届省赛我还在高三,所以没有机会参加,qaq 整体来说:我会的:A 简单搜索(背包也行吧) B跟POj2253查不到 最短路(很多都是并查集写的,不知道为啥) D 动态规划(算裸的吧) F 很水的模拟 H 贪心加简单的排序 G同POJ2567也算是简单的模拟 A: 10401: A.物资调度 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 103  Solved: 59 [Submit][Status][Web Board] Descriptio

nyoj1255 Rectangles(第七届河南省程序设计大赛)

题目1255 题目信息 运行结果 本题排行 讨论区 Rectangles 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 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

第七届省赛赛前交流赛部分题解

A题: Yougth's Game[Ⅲ]( 区间dp ) 这是在省赛前热身赛出的题目,可能是题目中有用到博弈的思想,很多人都在做,而且在尝试暴力.但是没有人往dp的方向上想. 题目类型:动态规划+博弈 分析:题意描述的很清楚,就是选择在两端取数,当前取的数不仅能够影响下一次的结果,而且能够影响后面的结果...又是一个求最优值,那么是不是可以往dp的方向上想了.区间dp 定义状态dp[ i ] [ j ] 为从 i 到 j 上A的得分,那么B的得分就是sum(i,j)-dp[ i ] [ j ]

nyoj1253 Turing equation(第七届河南省程序设计大赛)

题目1253 题目信息 运行结果 本题排行 讨论区 Turing equation 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 The fight goes on, whether to store  numbers starting with their most significant digit or their least  significant digit. Sometimes  this  is also called  the  "Endian

nyoj1248 海岛争霸(第七届河南省程序设计大赛)

题目1248 题目信息 运行结果 本题排行 讨论区 海岛争霸 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 神秘的海洋,惊险的探险之路,打捞海底宝藏,激烈的海战,海盗劫富等等.加勒比海盗,你知道吧?杰克船长驾驶着自己的的战船黑珍珠1号要征服各个海岛的海盜,最后成为海盗王. 这是一个由海洋.岛屿和海盗组成的危险世界.杰克船长准备从自己所占领的岛屿A开始征程,逐个去占领每一个岛屿.面对危险重重的海洋与诡谲的对手,如何凭借智慧与运气,建立起一个强大的海盗帝国. 杰克船长

nyoj1249 物资调度 (第七届河南省程序设计大赛)

物资调度 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述 某地区发生了地震,灾区已经非常困难,灾民急需一些帐篷.衣物.食品和血浆等物资.可通往灾区的道路到处都是塌方,70%以上的路面损坏,桥梁全部被毁.国家立即启动应急预案,展开史上最大强度非作战空运行动,准备向灾区空投急需物资. 一方有难,八方支援.现在已知有N个地方分别有A1,A2,-.,An个物资可供调配.目前灾区需要物资数量为M. 现在,请你帮忙算一算,总共有多少种物质调度方案. 假设某地方一旦被选择调配,则