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处理多表关联的方式或者说 ...
随机推荐
- Windows Azure 系列-- 使用Azure + Web API实现图片上传
1. 创建1个Azure账号,登录之后创建1个AzureStorage.左下方点Manage Access会看到Primary Access Key和Storage Account,记住它们的位置,等 ...
- ImportError: cannot import name gof
今天打开spyder说调试一个theano程序,但是import theano提示 ImportError: cannot import name gof 最后解决方案 pip install --u ...
- windows server 服务器添加免费域名证书的方法(Let's Encrypt)
在 windows server 服务器上可以通过 win-acme工具添加ssl 1.首先下载工具 https://github.com/PKISharp/win-acme/releases 最新版 ...
- redhat ent6.5使用centos yum
转载自:http://blog.csdn.net/zhngjan/article/details/20843465 搜狐镜像库:mirrors.sohu.com 163镜像库:mirrors.163. ...
- Poj1482
It's not a Bug, It's a Feature! Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 1428 ...
- Cocos2d-x学习笔记:CCSprite的使用总结
一.精灵创建及初始化 备注:默认锚点ccp(0.5,0.5),默认位置 ccp(0,0),contentSize为精灵图片尺寸 1.从图片文件创建 2.从帧缓存创建: 3.初始化及自定义大小 4. 从 ...
- 为Visual SVN使用签名后的域名证书
装了个VisualSVN Server管理代码,可每次浏览的时候都会提示证书有问题,要不要继续神马的,好烦人,于是搜索了一下免费SSL证书,申请了一个,虽然不是绿的,但总算是不报问题了. 下面是整个过 ...
- python将图片转base64,前端显示
https://blog.csdn.net/u013055678/article/details/71406746 <img src='xxxxxxx'> 跟这样的效果是一样的吧? ...
- 接口测试工具 — jmeter(关联)
1.正则表达式 1)添加正则表达式提取器 2)提取关联词 3)填写正则表达式 4)使用关联,其他请求使用${sign2}代替变量值 2. 1)添加提取器 2)填写变量值 3)使用关联,其他请求使用${ ...
- centos7 docker 安装配置
docker快速入门测试 ########################################## #docker安装配置 #环境centos7 #配置docker阿里源 echo '#D ...