题目链接:

http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255

描述

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.

输入
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 for each test case , a single line with a integer K , the length of the longest sequence of fitting rectangles.
样例输入
1
4
8 14
16 28
29 12
14 8
样例输出
2
 /*
问题 输入n个矩形的两条边长,计算并输出满足嵌套条件的最大长度,嵌套条件是其中一个矩形的一条边小于两一个矩形的一条边,而另
一条边小于等于另一个矩形的另一条边。 解题思路
比赛结束后,第一个重要的是读题读题读题。没有看到题目描述的最后一句话可以变换顺序及方向。导致没有排序,wa了7遍。
其实思路很简单,读入的时候将n个矩形尽可能的放平,就是短边放前面,再将所有矩形排序,排序规则是先比较第一条边,小的在前,
如果相等时比较第二条边,小的在前面(记得是小于,不确定的时候输出看一下)。然后就是最长上升子序列的模板了。
*/ #include<cstdio>
#include<algorithm>
using namespace std; struct REC{
int c,k;
}rec[]; int cmp(struct REC a,struct REC b){
if(a.c < b.c)
return ;
else if(a.c == b.c)
return a.k < b.k;//先按照c排,在按照k排的关键,wa了两次
return ;
} int ok(struct REC a,struct REC b){
if((a.c > b.c && a.k >= b.k) || (a.k > b.k && a.c >= b.c))
return ;
return ;
} int main()
{
int T;
scanf("%d",&T);
int n,i,j,a[];
while(T--){
scanf("%d",&n); int e1,e2;
for(i=;i<=n;i++){
scanf("%d%d",&e1,&e2);
rec[i].c=e1<e2?e1:e2;//保证短边在前
rec[i].k=e1<e2?e2:e1;
} sort(rec+,rec+n+,cmp); /*for(i=1;i<=n;i++)
printf("%d %d\n",rec[i].c,rec[i].k);*/
a[]=;
for(i=;i<=n;i++){
int temp=;
for(j=;j<i;j++){
if(ok(rec[i],rec[j])){
if(temp < a[j])
temp = a[j];
}
}
a[i] = temp +;
} int ans=-;
for(i=;i<=n;i++){
if(a[i] > ans)
ans = a[i];
}
printf("%d\n",ans);
}
return ;
}

Rectangles(第七届ACM省赛原题+最长上升子序列)的更多相关文章

  1. 山东省第七届ACM省赛------Fibonacci

    Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...

  2. 山东省第七届ACM省赛------Memory Leak

    Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...

  3. 山东省第七届ACM省赛------Reversed Words

    Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...

  4. 山东省第七届ACM省赛------Triple Nim

    Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...

  5. 山东省第七届ACM省赛------The Binding of Isaac

    The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...

  6. 山东省第七届ACM省赛------Julyed

    Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...

  7. sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)

    The Android University ACM Team Selection Contest Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里 ...

  8. 山东理工大学第七届ACM校赛-LCM的个数 分类: 比赛 2015-06-26 10:37 18人阅读 评论(0) 收藏

    LCM的个数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了 ...

  9. 山东理工大学第七届ACM校赛-完美素数 分类: 比赛 2015-06-26 10:36 15人阅读 评论(0) 收藏

    完美素数 Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 我们定义:如果一个数为素数,且这个数中含有7或3,那么我们称这个数为完美 ...

随机推荐

  1. (原创)c++中的类型擦除

    c++11 boost技术交流群:296561497,欢迎大家来交流技术. 关于类型擦除,可能很多人都不清楚,不知道类型擦除是干啥的,为什么需要类型擦除.有必要做个说明,类型擦除就是将原有类型消除或者 ...

  2. 三维数组—— 与宝玉QQ群交流 之三

    鞠老师 12:50:34 A[excel文件名][excel.sheet][sheet.行][sheet.列] 构成四维数组 计131-张振渊 12:51:54 a[1][0][0][3]? 鞠老师 ...

  3. [转载]腾讯专家:论高级DBA的自我修养

    作者介绍: 张秀云:2007年开始从事运维方面的工作,经历过网络管理员.linux运维工程师.DBA.分布式存储运维等多个IT职位.对linux运维.mysql数据库.分布式存储有丰富的经验.2012 ...

  4. 新品成熟EMR源码电子病历系统软件NET网络版CS可用带数据库全文档

    查看电子病历系统演示 医院医疗信息管理系统,EMR电子病历系统,功能模块如下所示: 1.住院医生站 2.住院护士站 3.病案浏览工作站 4.质量控制工作站 5.系统维护工作站  本店出售系统全套源码, ...

  5. WPF概述(硬件加速及分辨率无关性)

    一.名词解释 WPF(Windows Presentation Foundation),直译为Windows表示基础,是专门用来编写程序表示层的技术和工具. 大部分程序都是多层架构的,一般至少包含三层 ...

  6. 背水一战 Windows 10 (60) - 控件(媒体类): Pointer 涂鸦板, InkCanvas 涂鸦板

    [源码下载] 背水一战 Windows 10 (60) - 控件(媒体类): Pointer 涂鸦板, InkCanvas 涂鸦板 作者:webabcd 介绍背水一战 Windows 10 之 控件( ...

  7. Yii2 Apache + Nginx 路由重写

    一.什么是路由重写 原本的HTTP访问地址: www.test.com/index.php?r=post/view&id=100 表示这个请求将由PostController 的 action ...

  8. git关联githup和码云

    1.与已有的本地仓库关联git remote add origin git@github.com:michaelliao/learngit.git然后就可以协作开发push与pull 2.第二种方法直 ...

  9. yarn 学习 小记

    官网:https://yarnpkg.com/zh-Hans/docs/installing-dependencies 简介:包管理工具,和npm类似主要特点:快速.安全.可靠 快速:本地安装包后,会 ...

  10. js基于json的级联下拉框

    级联下拉列表是项目中常用到的.比如省市县,比如企业性质等,做成一个js通用组件, 在静态页出来后可以直接插入,将数据和html静态页做一个解耦. 贴出来抛砖引玉吧. /** * @author sun ...