题目链接:

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. AngularJS 启动执行过程

    一.浏览器下载HTML/CSS/JavaScript等 当你转到一个页面地址后,浏览器先回下载这个HTML,同时,会开启一些辅助线程下载所关联的script标签和link标签里引用的文件. 二.浏览器 ...

  2. 索引视图DEMO2

    use tempdb ----在创建视图和所有底层表时,必须打开ANSI_NULLS以及QUOTED_IDENTIFIER选项 --SET ANSI_NULLS ON --GO --SET QUOTE ...

  3. tfs查看最近签入记录及文件

    在团队资源管理=>源代码管理资源管理器=>选择某个最近签入的文件夹=>右键=>查看历史记录=>双击某个文件夹 就能看到最近变更集文件

  4. ASP.NET MVC高亮显示当前页面菜单

    1.创建MvcHtmlExtension扩展类 public static class MvcHtmlExtension { public static MvcHtmlString MenuLink( ...

  5. Webapi文件上传

    1/  multipart/form-data方式 using Abp.UI; using Abp.Web.Models; using System; using System.Collections ...

  6. 微服务统一登陆认证怎么做?JWT ?

    无状态登录原理 1.1.什么是有状态? 有状态服务,即服务端需要记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行请求的处理,典型的设计如tomcat中的session. 例如登录:用户登 ...

  7. 对股市骗子内部的一次apt测试

    i春秋作家:jasonx 前言 由于这件事情搞了很久,中间很多截图已经没有了,所以文章中出现的部分截图是后面截的. 文中很多地方涉及敏感信息,为了我的人身安全,打码比较严重,还请多多理解. 起因 前不 ...

  8. D3.js的基础部分之数组的处理 数组的排序和求值(v3版本)

    操作数组   D3提供了将数组洗牌.合并等操作,使用起来是很方便的.   d3.shuffle(array,[,lo[,ji]]) : //随机排列数组. d3.merge(arrays) :   / ...

  9. job任务执行流程与分区机制

    job任务执行流程    1.run job阶段        ①收集整个job的环境信息(比如通过conf设定的参数,还有mapperClass,reducerClass,以及输出kv类型)     ...

  10. python学习笔记10-文件操作

    能调用方法的一定是对象.文件本身也是一个对象.有很多自己内置的方法 #操作文件第一件事 建立文件对象 open函数 # 参数一:文件路径 绝对路径和相对路径都可以 # 参数二:模式选择 ‘r’ 读模式 ...