POJ 3636 Nested Dolls

从零开始 使用OMNET++结合VEINS,INET和SUMO的联合仿真 搭建仿真的环境,导入VEINS和INET开源库,使用INET库中提供的网络协议和功能模型来模拟通信协议和网络功能,使用SUMO创建道路网络和车辆轨迹,并导出到OMNeT++中 在OMNeT++中使用VEINS通过socket和SUMO连接,借助VEINS实现的TRACI接口来设置车辆相关的行为和场景,最后在OMNET++中结合VEINS,SUMO和INET运行联合仿真实验,并分析车辆在遇到紧急情况下的通信状况和具体行为 阅读详情
Nested Dolls
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 8301 Accepted: 2258

Description

Dilworth is the world's most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls of different sizes of which the smallest doll is contained in the second smallest, and this doll is in turn contained in the next one and so forth. One day he wonders if there is another way of nesting them so he will end up with fewer nested dolls? After all, that would make his collection even more magnificent! He unpacks each nested doll and measures the width and height of each contained doll. A doll with width w1 and height h1 will fit in another doll of width w2 and height h= if and only if w1 < w2 andh1 < h2. Can you help him calculate the smallest number of nested dolls possible to assemble from his massive list of measurements?

Input

On the first line of input is a single positive integer 1 ≤ t ≤ 20 specifying the number of test cases to follow. Each test case begins with a positive integer 1 ≤ m ≤ 20000 on a line of itself telling the number of dolls in the test case. Next follow 2m positive integers w1, h1,w2, h2, ... ,wm, hm, where wi is the width and hi is the height of doll number i. 1 ≤ wi, hi ≤ 10000 for all i.

Output

For each test case there should be one line of output containing the minimum number of nested dolls possible.

Sample Input

4
3
20 30 40 50 30 40
4
20 30 10 10 30 20 40 50
3
10 30 20 20 30 10
4
10 10 20 30 40 50 39 51

Sample Output

1
2
3
2

Source

Nordic 2007


题意:给你n个娃娃的h(高度),w(宽度),如果一个娃娃的h和w都分别严格小于另一个娃娃的h和w,第一个娃娃就可以套进第二个娃娃

多个娃娃套在一起组成的娃娃被看成一个娃娃

请你求出得到娃娃的最少数量

没有我开始想象的那么简单(开始以为dp)

正解是这样,首先按照每个娃娃的w升序排序,如果w相等就按照h降序排序,那么我们就要找出对于h的最少单调递增子序列的个数

求子序列的个数用到了类似于dp的方法,先定义一个数组b,里面存的是每个单调递增子序列的最大元素,也就是说b数组里元素数量就是求出的子序列个数

依次枚举每一个娃娃在b中二分查找判断有没有比当前娃娃的h值还要小的,有就将当前h换成最大元素,否则就将h添加到b数组中

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=2e4+5,inf=1e9;
int t,n,b[maxn];
struct wk{int w,h;}s[maxn];
bool cmp(wk a,wk b){return a.w==b.w?a.h>b.h:a.w<b.w;}
int main(){
	cin>>t;
	while(t--){
		scanf("%d",&n);
		memset(s,0,sizeof(s));
		memset(b,0,sizeof(b));
		int i,pos,len=1;
		for(i=1;i<=n;i++)
		    scanf("%d%d",&s[i].w,&s[i].h);
		sort(s+1,s+1+n,cmp);
		b[1]=s[1].h;
		for(i=2;i<=n;i++){
			int l=1,r=len;
			while(l<=r){
				int mid=(l+r)>>1;
				if(b[mid]>=s[i].h)l=mid+1;
				else r=mid-1;
			}
			b[l]=s[i].h;
			if(l>len)len++;
		}
		printf("%d\n",len);
	}
}


CANape快速上手 文章帮助记录CANape学习过程。 阅读详情

相关推荐

即梦 AI 全功能零基础详细教程(纯技术版)

即梦 AI 是一款多模态 AI 生成工具,主打文本生成视频、图片生成视频、角色一致性生成、音画同步等核心功能,依托自研 AI 视觉模型,实现从文本 / 图片 / 音频素材输入,到高清视频、图像内容输出的全流程 AI 创作,支持短视频、短剧、创意素材等多场景创作,具备操作门槛低、生成效率高、画面可控性强的技术特点。@为工具内置引用指令,作用是锁定指定素材 / 角色,强制 AI 按照该素材的核心特征生成内容,无额外付费、解锁要求,免费使用。剧本拆分:将短剧拆分为单镜头(15 秒内 / 个)

2501_92061023的博客 5998

HDU 1677 Nested Dolls

Problem Description Dilworth is the world’s most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls of different sizes of which the sma...

weixin_34387468的博客 188

Unity 数字孪生实战:PiXYZ Plugin工业模型高效处理指南

本文是Unity数字孪生实战指南,重点介绍了如何使用PiXYZ Plugin高效处理工业CAD模型。针对工业模型导入Unity时面临的格式壁垒、数据爆炸和资产混乱等核心痛点,文章提供了从环境安装、基础导入到智能减面、资产清理的完整解决方案,并分享了预设自动化、运行时导入等高级技巧与性能优化策略,帮助开发者快速打通工业设计与实时交互流程。

weixin_29009501的博客 262

SPOJ 3943 Nested Dolls

【SPOJ 3943 Nested Dolls】 Time Limit: 156MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu  【Description】Dilworth is the world's most prominent collector of Russian nested dolls:he literall

Freddddd 903

Visual SLAM算法笔记

最近在学习SLAM算法,这里作为阅读笔记记录和总结一下。对经典的单目SLAM/VO算法做了摘要和总结,比如Nister VO、MonoSLAM、PTAM、ORB-SLAM、LSD-SLAM、SVO、DSO等,对几个单目和IMU的融合算法也做了简单总结,比如MSCKF、OKVIS、IMU-Preintegration等。

MulinB的技术博客 3万+

【NIFI】实现HANA->ORACLE数据同步

实现 HANA->ORACLE数据同步。

weixin_43159039的博客 1514

Nested Dolls

Nested Dolls Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1727    Accepted Submission(s): 484 Problem Description Dilworth is the wo

wenlovingliu的专栏 696

不用Root!这些隐藏代码能一键开启安卓诊断端口(小米/OPPO/魅族机型实测)

本文提供了一份无需Root权限即可开启安卓手机诊断端口的实用指南。通过拨号盘输入特定隐藏代码,小米、OPPO、魅族等机型的用户可以一键激活此工程模式,从而连接电脑进行基带数据备份(如QCN文件)或故障排查。文章详细列出了各品牌指令、操作验证步骤,并强调了备份IMEI等关键数据的重要性与操作风险,旨在帮助用户在紧急情况下修复网络问题。

weixin_29260291的博客 281

hdu 1677 Nested Dolls

Problem DescriptionDilworth is the world’s most prominent collector of Russian nested dolls: he literally has thousands of them! You know, the wooden hollow dolls of different sizes of which the smalle

ACM__dongsheng的博客 496

蓝桥杯FPGA赛道积分赛

代码如下: 按键驱动 代码如下 按键驱动 代码如下: 顶层文件 按键驱动 数码管驱动 声明:本代码借鉴网络资料,如有侵权和错误请联系作者删除。我是从寒假开始备赛的,由于我基础不行,备赛过程中也是混混呃呃的,备赛效率不高,总体来说备赛不认真,有点拖拉,但是最后我也坚持备赛到了今天,在备赛过程中,即复习了旧的东西,也学到了新的东西,总结起来还是有点收获的,后天北京、天津、河北地区就要进行省赛了,我会全力以赴,不管结果怎么样,尽力就好,最后祝大家都能

weixin_69804913的博客 2012

深度学习的unfold操作

对于彩色图像这样的三维数据,unfold操作会对每个通道分别进行上述的二维展开操作。例如,一个 RGB 图像,在对其进行unfold操作时,红色通道、绿色通道和蓝色通道的数据都会被独立地按照定义的窗口和步长展开,然后将这些展开后的通道数据按照原来的通道顺序组合在一起,形成新的张量。与我们熟悉的卷积类似,unfold也是使用一个特定大小的窗口和步长自左至右、自上至下滑动,不同的是,卷是滑动后与核求乘积(所以取名为卷积),而unfold滑动后不求乘积,是将窗口内的数据展开。

xulibo5828的博客 2175

Nested_Dolls(偏序集)

Nested DollsTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 3570Accepted: 949DescriptionDilworthis the worlds most prominent collector of Ru

carrot12_24的专栏 498

RLHF的数学表示

RLHF(Reinforcement Learning with Human Feedback)是一种结合了强化学习和人类反馈的机器学习方法。它通常用于训练智能体(agent)在复杂环境中做出决策,同时利用人类的反馈来指导和改进学习过程。RLHF 没有一个统一的数学表示式,因为它依赖于具体的应用场景和实现细节。然而,我们可以从强化学习和人类反馈的角度来描述RLHF的一些关键数学概念。

xw555666的博客 691

POJ3636Nested Dolls

Nested Dolls Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description Dilworth is the world's most prominent collector of Russian nest

逝水流年轻染尘 672

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

poj3636 Nested Dolls

分析:偏序关系。如果采用poj1065的方法超时,所以用一个数组D[2100],吧每个偏序链的末端 保存起来,不断更新。 #include #include #include using namespace std; struct node{ int w,h; }doll[21000],D[2100]; int cmp(node x,node y) { if(x.w!=

Stay hungry,stay foolish! 861

vb 6.0并口开发操作实例

vb6并口开发,简体中文,试例内有inpout32.dll动态链接库

poj3636--Nested Dolls

Nested Dolls Time Limit:1000MS Memory Limit:65536K Total Submissions:7943 Accepted:2158 Description Dilworth is the world's most prominent collector of Russi...

dixi7825的博客 200

【贪心】poj3636 nested dolls

好水啊好水啊。。。 不过输入输出有点恶心,cout和cin就超时,scanf和printf就AC了。。。 #include #include #include #include using namespace std; struct Node{ int w,h; }; int cmp(const void* elem1,const void*elem2){ Node *p,*q; p=

BananaTree 793

POJ 3636 Nested Dolls -(最长上升子序列)

题目链接:http://poj.org/problem?id=3636 最小链划分数 = 最长反链长度 按如下关系排序: w1&gt;w2∨(w1=w2∧h1≤h2) w_1 \gt w_2 \lor (w_1 = w_2 \land h_1 \le h_2) w1​>w2​∨(w1​=w2​∧h1​≤h2​) 定义反链: w1≥w2∧h1≤h2 w_1 \ge w_2 \land ...

rsy56640的博客 1535

poj_3636Nested Dolls

Nested Dolls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7225   Accepted: 1932 Description Dilworth is the world's most prominent collector of Russian ne

晚晴小筑 967

POJ 3636 俄罗斯Nested Dolls 贪心二分 动态规划

首先要区分#include 中的qsort与C++ STL algorithm中的sort,后者只有三个参数且比较函数写法较简单些 类似于POJ 1065,差异有二,其一是排序方式下降,其二是要求下降且不相等但是用常规的贪心会超时,用二分优化后不超时,注意对l递增排,对w递减排// 类似于POJ 1065,差异有二,其一是排序方式下降,其二是要求下降且不相等 // 上面这种解法会超时,用二分优化

Coding for Dreams 3414

POJ3636Nested Dolls[DP LIS]

Nested Dolls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8323   Accepted: 2262 Description Dilworth is the world's most prominent collector of Russian ne...

weixin_33912445的博客 149

【POJ3636】Nested Dolls Dilworth定理(偏序集定理二)

题意:别问我,直接扒1065或者1548代码,然后改一下cmp函数为y值递减,然后最长下降子序列改成最长不上升子序列,收工。 贴代码:(当然你要看这个定理可以去我的前两篇博客看) 啊,这个的求最长不上升子序列必须nlogn了,n^2会TLE了~~ #include #include #include #define N 50000 #define inf 0x3f3f3f3f usin

辗转山河弋流歌 1313
上一篇: Codeforces Round #367 (Div. 2) [C] Hard Problem
下一篇: Codeforces Round #367 (Div. 2) [D] Vasiliy's Multiset(01字典树模板)
SuperGate
博客等级 码龄11年 68粉丝 252原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值