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,那么我们称这个数为完美 ...
随机推荐
- poj1321 DFS
棋盘问题 Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u Java class n ...
- vlookup返回多个结果
http://www.360doc.com/content/12/1021/15/7665211_242782107.shtml =IFERROR(VLOOKUP(D2&ROW(A1),IF( ...
- mysql 幻象读
[sql] view plain copy CREATE TABLE `t100` ( `id` bigint(20) NOT NULL default '0', `value` varchar(32 ...
- [NewCode 4] 替换空格
题目描述 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 最直接的方式, ...
- linux的cd命令
面试时被问到了一个命令是什么意思 cd - 还真是一脸懵逼.... 回来试了下 发现真的是一个神奇的命令~ 会跳到之前目录下并输出, 比如
- C语言判断进程是否存在
#include <windows.h> #include <tlhelp32.h> //进程快照函数头文件 #include <stdio.h> bool get ...
- MyBatis全局配置文件标签详解
一.全局配置文件结构 configuration 配置 properties 属性:可以加载properties配置文件的信息 settings 设置:可以设置mybatis的全局属性 typeAli ...
- github或码云协同开发
协同开发 1.引子:假如三个人共同开发同一份代码,每个人都各自安排了任务,当每个人都完成了一半的时候,提交不提交呢? 要提交,提交到dev吗,都上传了一半,这样回家拿出来的代码根本跑不起来.所以, 为 ...
- supervisor 管理uwsgi 进程
Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动 重启.它是通过fork/exec的方式把这些被管理的进 ...
- odoo 开发基础 -- 视图之xpath语法
odoo 视图函数 在整个项目文件中,结构并不是十分明显,虽然它也遵循MVC设计,类比django的MTV模式,各个模块区分的十分明显,在Odoo中,视图的概念不是特别明显,很多时候,我们会将调用模型 ...