Nested DollsHDU1677
/*题意:有n个矩形,用长和宽表示,如果一个的长和宽都比另一个小,那么这个嵌放在另一个中
所以先对w从大到小排序,w一样的按h从小到大排序,那么就从后面的箱子往前找,只要前面找到一个人h比自己大的就放入c[j]=p[i].h;
否则如果自己的h比前面的都大,那么必定询问到c所存的递增序列的长度+1处,那么个数加1,长度加1,把此事的h放在在c的末端
这个过程和最大递增子序列的找值过程类似,但是并不是求最长递增,只是利用这个过程,所以二分查找稍微有些改变,如果还是按照
最长公共子序列的二分查找,那么h相同的会被覆盖掉比如数据1 1 1 1 2 2 2 2,其中一个2 2会被另一个2 2覆盖掉,导致结果为3*/ #include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int w,h;
}p[];
int cmp(const node a,const node b)
{
if(a.w==b.w) return a.h<b.h;
return a.w>b.w;
}
int find(int *p,int len,int n)
{
int l=,r=len;
int mid=(l+r)/;
while(l<=r)
{
if(n>=p[mid]) l=mid+;
else r=mid-;
mid=(l+r)/;
}
/*while(l<=r)//最长递增子序列的二分查找
{
if(n>p[mid]) l=mid+1;
else if(n<p[mid]) r=mid-1;
else return mid;//递增不应许有两个高度一样的,所以要覆盖
mid=(l+r)/2;
}*/
return l;
}
int main()
{
int i,j,k,n,m;
int T;
int c[];
scanf("%d",&T);
while(T--)
{
memset(c,,sizeof(c));
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d%d",&p[i].w,&p[i].h);
}
sort(p,p+n,cmp);
int len=;
c[]=-;
c[]=p[].h;
for(i=;i<n;i++)
{
j=find(c,len,p[i].h);
c[j]=p[i].h;
if(j==len+) len++;
}
printf("%d\n",len);
}
return ;
}
Nested DollsHDU1677的更多相关文章
- Nested Loops join时显示no join predicate原因分析以及解决办法
本文出处:http://www.cnblogs.com/wy123/p/6238844.html 最近遇到一个存储过程在某些特殊的情况下,效率极其低效, 至于底下到什么程度我现在都没有一个确切的数据, ...
- Error on line -1 of document : Premature end of file. Nested exception: Premature end of file.
启动tomcat, 出现, ( 之前都是好好的... ) [lk ] ERROR [08-12 15:10:02] [main] org.springframework.web.context.Con ...
- SQL Tuning 基础概述06 - 表的关联方式:Nested Loops Join,Merge Sort Join & Hash Join
nested loops join(嵌套循环) 驱动表返回几条结果集,被驱动表访问多少次,有驱动顺序,无须排序,无任何限制. 驱动表限制条件有索引,被驱动表连接条件有索引. hints:use_n ...
- [LeetCode] Nested List Weight Sum II 嵌套链表权重和之二
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- [LeetCode] Flatten Nested List Iterator 压平嵌套链表迭代器
Given a nested list of integers, implement an iterator to flatten it. Each element is either an inte ...
- [LeetCode] Nested List Weight Sum 嵌套链表权重和
Given a nested list of integers, return the sum of all integers in the list weighted by their depth. ...
- 禁用nested loop join里的spool
禁用nested loop join里的spool 转载自: https://blogs.msdn.microsoft.com/psssql/2015/12/15/spool-operator-and ...
- Android Fragment使用(二) 嵌套Fragments (Nested Fragments) 的使用及常见错误
嵌套Fragment的使用及常见错误 嵌套Fragments (Nested Fragments), 是在Fragment内部又添加Fragment. 使用时, 主要要依靠宿主Fragment的 ge ...
- 1122MySQL性能优化之 Nested Loop Join和Block Nested-Loop Join(BNL)
转自http://blog.itpub.net/22664653/viewspace-1692317/ 一 介绍 相信许多开发/DBA在使用MySQL的过程中,对于MySQL处理多表关联的方式或者说 ...
随机推荐
- win7(64位)+vs2008配置Directshow
参考链接:http://zhuyanfeng.com/archives/1663 PC环境:win7 64bit + vs2008 1.下载64位的win7 SDK2.安装过程中遇到错误(必须要卸载v ...
- opencv2.4.9+VS2010配置
opencv2.4.9 https://pan.baidu.com/s/15b5bEY65R4CptayEYVAG4A 安装包路径:D:\文件及下载相关\文档\Tencent Files\845235 ...
- 怎样開始学习ADF和Jdeveroper 11g
先给一些资料能够帮助刚開始学习的人開始学习ADF和Jdeveloper11g 1.首先毫无疑问,你要懂java语言. 能够看看Thinking In Java, 或者原来sun的网上的一些文档Sun' ...
- 为什么要使用docker
1. 为什么要使用Docker Docker容器虚拟化的好处 Docker项目的发起人和Docker Inc.的CTO Solomon Hykes认为,Docker在正确的地点.正确的时间顺应了正确的 ...
- css3动画效果:3 3D动画
立方体旋转动画效果 css #container{ width: 400px; height: 400px; ; ; -webkit-perspective-origin:50% 225px; per ...
- PageCache 在查询中的作用很大
百度Elasticsearch-产品描述-介绍-百度云 https://cloud.baidu.com/doc/BES/FAQ.html#.51.46.57.73.73.7E.71.4C.6F.AA. ...
- JavaScript四种数值取整方法
一.Math.trunc() 1.定义 Math.trunc()方法去除数字的小数部分,保留整数部分. 2.语法 Math.trunc(value) 3.示例 console.log(Math.tru ...
- C#中Windows通用的回车转Tab方法
标签: windowsc#textboxbuttondropdownobject 2007-03-28 09:37 2773人阅读 评论(0) 收藏 举报 分类: C#(5) 版权声明:本文为博主 ...
- Spring 框架的 applicationContext.xml 配置文件
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- Java 之反射机制
java 语言的反射机制 - 在运行状态中,对于任意一个类 (class 文件),都能够知道这个类的所有属性和方法; - 能动态获取类中的信息,也可以理解为对类(字节码文件)的解剖 描述字节码文件的类 ...