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处理多表关联的方式或者说 ...
随机推荐
- 【BZOJ】3396: [Usaco2009 Jan]Total flow 水流 (最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=3396 裸的最大流跑过.. #include <cstdio> #include < ...
- echarts使用要点
- C#基础语言知识--编译和执行过程
http://blog.csdn.net/stive_sourcexin/article/details/51329697
- JS-校验表单后提交表单的三种方法总结
第一种: <script type="text/javascript"> function check(form) { if(form.userId.value=='' ...
- 2154: Crash的数字表格
2154: Crash的数字表格 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 3372 Solved: 1258[Submit][Status][ ...
- [hihoCoder] Trie树
This is a application of the Trie data structure, with minor extension. The critical part in this pr ...
- 前端模板<script type="text/template" id="tmpl">
前端模板, 比连接字符串好用多了, 还可以使用循环\判断等语句, 减少工作量 <script type="text/template" id="member-tmp ...
- mysql查询某天是本年第几周
SELECT WEEK(date_add('2012-12-31',interval 6 day),2);
- 用jQuery的attr()设置option默认选中无效的解决 attr设置属性失效
表单下拉选项使用selected设置,发现第一次默认选中成功,在页面不刷新的情况下,再次下拉,selected属性设置了,默认选中不生效 在手机端有些浏览器用jQuery的attr()方法设置sele ...
- 修改jquery.automeplete,使其支持value匹配
原生只会去匹配label,可在实际使用中,可能需要匹配的值并不需要显示在label中,经过添加一个matchType属性解决 1.加入matchType选项,并默认为原生匹配 $.widget(&qu ...