Rectangles(第七届ACM省赛原题+最长上升子序列)
题目链接:
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省赛原题+最长上升子序列)的更多相关文章
- 山东省第七届ACM省赛------Fibonacci
Fibonacci Time Limit: 2000MS Memory limit: 131072K 题目描述 Fibonacci numbers are well-known as follow: ...
- 山东省第七届ACM省赛------Memory Leak
Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...
- 山东省第七届ACM省赛------Reversed Words
Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...
- 山东省第七届ACM省赛------Triple Nim
Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...
- 山东省第七届ACM省赛------The Binding of Isaac
The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...
- 山东省第七届ACM省赛------Julyed
Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...
- sdut 2162:The Android University ACM Team Selection Contest(第二届山东省省赛原题,模拟题)
The Android University ACM Team Selection Contest Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里 ...
- 山东理工大学第七届ACM校赛-LCM的个数 分类: 比赛 2015-06-26 10:37 18人阅读 评论(0) 收藏
LCM的个数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了 ...
- 山东理工大学第七届ACM校赛-完美素数 分类: 比赛 2015-06-26 10:36 15人阅读 评论(0) 收藏
完美素数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 我们定义:如果一个数为素数,且这个数中含有7或3,那么我们称这个数为完美 ...
随机推荐
- CentOS 7.0 Firewall防火墙配置
启动停止 获取firewall状态 systemctl status firewalld.service firewall-cmd --state 开启停止防火墙 开机启动:systemctl ena ...
- docker容器中的peewee如何连接已有的容器中的数据库
首先,两个容器必须是在同一网络下,有2个办法. 一个是在同一个docker-compose.yml文件下使用links参数,比如: version: '3' services: redis: imag ...
- SQL SERVER的锁机制(四)——概述(各种事务隔离级别发生的影响)
六.各种事务隔离级别发生的影响 修改数据的用户会影响同时读取或修改相同数据的其他用户.即这些用户可以并发访问数据.如果数据存储系统没有并发控制,则用户可能会看到以下负面影响: · 未提交的依赖关系(脏 ...
- C# 动态创建数据库三(MySQL)
前面有说明使用EF动态新建数据库与表,数据库使用的是SQL SERVER2008的,在使用MYSQL的时候还是有所不同 一.添加 EntityFramework.dll ,System.Data.En ...
- UCore-Lab1
日期:2019/3/31 内容:makefile分析: 一."Makefile"分析 1.1 ucore.img lab1已有的源文件 目录 文件 boot asm.h.boo ...
- ubuntu下nodejs源码安装
1.从github选择下载自己要安装的nodejs版本,https://github.com/nodejs/node/releases,我下载的版本是node-9.11.2.tar.gz 2.解压no ...
- GC日志时间分析
在GC日志里,一条完整的GC日志记录最后,会带有本次GC所花费的时间,如下面这一条新生代GC: [GC [DefNew: 3298K->149K(5504K), secs] [Times: us ...
- mybatis 全局配置文件
传送门:mybatis XML 映射配置文件官方文档 配置文件中的标签顺序不能颠倒,否则会报错. <?xml version="1.0" encoding="UTF ...
- 将页面中表格数据导出excel格式的文件(vue)
近期由于项目需要,需要将页面中的表格数据导出excel格式的文件,折腾了许久,在网上各种百度,虽然资料不少,但是大都不全,踩了许多坑,总算是皇天不负有心人,最后圆满解决了. 1.安装相关依赖(npm安 ...
- WebRTC开发基础(WebRTC入门系列1:getUserMedia)
什么是WebRTC WebRTC由IETF(Internet Engineering Task Force——互联网工程任务组)和W3C(World Wide Web Consortium——万维网联 ...