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处理多表关联的方式或者说 ...
随机推荐
- js 自定义类
将近20年前,Javascript诞生的时候,只是一种简单的网页脚本语言.如果你忘了填写用户名,它就跳出一个警告. 如今,它变得几乎无所不能,从前端到后端,有着各种匪夷所思的用途.程序员用它完成越来越 ...
- linux 安装php 然后跟nginx整合
php-fpm安装配置 nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端. nginx一般是把请求发fastcgi管理 ...
- c++ 指针(不断更新)
c++指针只能说博大精深,在用的时候感觉好晕 1.指针类型转换 /* 在指针的强制类型转换:ptr1=(TYPE*)ptr2中,如果sizeof(ptr2的类型)大于sizeof(ptr1的类型), ...
- cordova添加android平台时选择安装版本: requirements check failed for jdk 1.8
提示如上: 因为android-24 需要 jdk1.8 ,这里指定 android@5.1.1 即可 android-23,如下图
- Java获取任意时间、时间字符串
/* * 获取时间字符串*/public String getCurrentTime() { SimpleDateFormat sdf = new SimpleDateFormat("yyy ...
- Understanding Tensorflow using Go
原文: https://pgaleone.eu/tensorflow/go/2017/05/29/understanding-tensorflow-using-go/ Tensorflow is no ...
- MAPISession(EventID9646-MS-ExchangeIS)
查看邮箱登录信息: Get-LogonStatistics jsmith | Sort-Object clientipaddress | Format-Table Get-LogonStatistic ...
- scrapy spider
spider 定义:在spiders文件夹中由用户自定义,继承scrapy.Spider类或其子类 Spider并没有提供什么特殊的功能. 其仅仅请求给定的 start_urls/start_requ ...
- 让Windows Server 2008+IIS 7+ASP.NET支持10万个同时请求
具体设置如下: 1. 调整IIS 7应用程序池队列长度 由原来的默认1000改为65535. IIS Manager > ApplicationPools >Advanced Settin ...
- (4.2)SQL Server 客户端连接的问题
转自:http://blog.51cto.com/jimshu/1395199 经常遇到 SQL Server 客户端无法连接到SQL Server 实例(服务).现在将这类问题归纳如下: 一.SQL ...