Zoj 1025 Wooden Sticks

ZJU_ACM_All_Anwer 搞编程的都知道的浙江大学A 题库.本书 集了所有经 Z 题解集,集合并附 Mathimaticsumerical algorithms 数值算法 ZJU_Main 主页 下一页 ZJU 题型分类 文演整理版 2008-3-23 数论: 1007 Numerical Summation of a Series 简单题,还是蛮有意思的 1045 HangOver 简单题 1049 I Think I Need a Houseboat 简单题 1028 Flip and Shift 简单题,可以DP/BFS/……,但是实际上有数学方法可直接判断出来 1026 Modular multiplication of polynomials 简单题,有比较简单的好算法 1307 Packets 简单题,不过也蛮经典的…… 1312 Prime Cuts 简单题 1334 Basically Speaking 简单题 1337 Pi 简单题 1342 Word Index 简单题 1349 Four Quarters 简单题 1350 The Drunk Jailer 简单题 1352 Number Base Conversion 简单题 1353 Unimodal Palindromic Decompositions 规模不大,所以是简单题…… 1354 Extended Lights Out 简单题 1362 Game Prediction 简单题 1365 Mileage Bank 简单题 1382 A Simple Task 简单题 1383 Binary Numbers 简单题 1403 Safecracker 简单题 1408 The Fun Number System 简单题 1486 Color the Tree 简单题 1487 Playing Cards 简单题 1489 2^x mod n = 1 简单题,应该有好算法,不过枚举就可以过…… 1503 One Person "The Price is Right" 简单题,POI Eggs的翻版 1512 Water Treatment Plants 简单题,组合计数 1526 Big Number 简单题,不过O(1)和O(n)还是有区别的:) 1529 Enigmatic Travel 简单题,不过个人感觉题目描述很令人费解 1530 Find The Multiple 简单题 1537 Playing with a Calculator 简单题 1577 GCD & LCM 简单题,分区联赛的题…… 1005 Jugs 简单题 1543 Stripies 简单题 1569 Partial Sums 简单题 1062 Trees Made to Order 简单题 1070 Bode Plot 简单题 1073 Round and Round We Go 简单题,142857,我喜欢^_^ 1078 Palindrom Numbers 简单题 1086 Octal Fractions 简单题 1199 Point of Intersection 简单题 1104 Leaps Tall Buildings 简单题 1110 立即下载

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a stick. The setup times are associated with cleaning operations and changing tools and shapes in the machine. The setup times of the woodworking machine are given as follows:

(a) The setup time for the first wooden stick is 1 minute.
(b) Right after processing a stick of length l and weight w , the machine will need no setup time for a stick of length l' and weight w' if l<=l' and w<=w'. Otherwise, it will need 1 minute for setup.

You are to find the minimum setup time to process a given pile of n wooden sticks. For example, if you have five sticks whose pairs of length and weight are (4,9), (5,2), (2,1), (3,5), and (1,4), then the minimum setup time should be 2 minutes since there is a sequence of pairs (1,4), (3,5), (4,9), (2,1), (5,2).


Input

The input consists of T test cases. The number of test cases (T) is given in the first line of the input file. Each test case consists of two lines: The first line has an integer n , 1<=n<=5000, that represents the number of wooden sticks in the test case, and the second line contains n 2 positive integers l1, w1, l2, w2, ..., ln, wn, each of magnitude at most 10000 , where li and wi are the length and weight of the i th wooden stick, respectively. The 2n integers are delimited by one or more spaces.


Output

The output should contain the minimum setup time in minutes, one per line.


Sample Input

3
5
4 9 5 2 2 1 3 5 1 4
3
2 2 1 1 2 2
3
1 3 2 2 3 1


Output for the Sample Input

2
1
3


排序之后暴力求解就OK了

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

struct Node{
	int L,W;
}num[10000];

int flag[10000];

bool cmp(Node a,Node b)
{
	if(a.L!=b.L)
		return a.L<b.L;
	return a.W<b.W;
}

int main()
{
	int T,n;
	int i,cnt,ok;
	Node tmp;

	scanf("%d",&T);

	while(T--)
	{
		scanf("%d",&n);
		for(i=1;i<=n;i++)
			scanf("%d%d",&num[i].L,&num[i].W);
		sort(num+1,num+1+n,cmp);
/*		printf("\n");
		for(i=1;i<=n;i++)
			printf("%d %d\n",num[i].L,num[i].W);
		printf("\n");
*/		memset(flag,0,(n+100)*sizeof(flag[0]));
		cnt=0;
		ok=1;
		while(ok)
		{
			ok=0;
			for(i=1;i<=n;i++)
			{
				if(ok==0 && flag[i]==0)
				{
					ok=1;
					flag[i]=1;
					cnt++;
					tmp=num[i];
					continue;
				}
				if(flag[i]==0 && tmp.L<=num[i].L && tmp.W<=num[i].W)
				{
					tmp=num[i];
					flag[i]=1;
				}
			}
		}
		printf("%d\n",cnt);
	}

	return 0;
}


Windows打印体系结构之Windows内置打印驱动程序 时间是一种很残酷的东西,它只会冲淡能够冲淡的,但也会洗尽铅华帮你留下该留下的。1.3.4、Windows内置打印驱动程序现在的Windows下的打印机驱动程序通常分为V4打印机驱动程序(V4 Printer Driver)、XPS打印机驱动程序(XPSDrv)、微软通用打印机驱动程序(Microsoft UniversalPrinter Driver)、微软PostScri... 阅读详情

相关推荐

python数据分析与可视化

Python数据分析主要包括数据清洗、数据探索和数据可视化三个部分。数据清洗是数据分析的重要环节,主要是对数据进行预处理,包括缺失值处理、异常值处理、数据类型转换等。数据探索则是通过对数据进行初步分析,了解数据的分布和特征,为后续的数据分析提供基础。数据可视化则是将数据以图形化的方式呈现,帮助人们更好地理解和分析数据。

2301_82032652的博客 7744

ACM题解——贪心专题——木头加工

ACM题解——贪心之木头加工 题目描述 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to

Biangbangbing的博客 646

【Bluetooth蓝牙开发】一、开篇词 | 打造全网最详细的Bluetooth开发教程

1、开篇词 2、蓝牙开发入门 3、蓝牙协议栈总览 4、蓝牙协议栈——物理层 5、蓝牙协议栈——链路层 6、蓝牙协议栈——传输层 7、蓝牙协议栈——L2CAP协议 8、蓝牙协议栈——ATT协议 9、蓝牙协议栈——GATT协议 10、蓝牙通信流程分析 11、蓝牙协议栈——Bluez交叉编译 12、蓝牙调试工具汇总

Donge's Blog 1万+

POJ - 1065 Wooden Sticks

Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs som

Lakersman的博客 664

华为OD机试真题2026双机位C卷 Python&JS 实现【明日之星选举】

给定一组选票votes。votes[i]代表第 i 张选票的内容,包含一个字符串"zhangsan,hanmei",表示推荐zhangsan为明日之星,反对 hanmei 称为明日之星。赞成或反对使用逗号(,)分割。 给定一个数组n,表示最后将筛选出赞成票最多的n个人,如果赞成票相同,则反对票越少,排序越靠前;如果赞成票和反对票都相同,则按照姓名字典序升序排序。

MISAYAONE的博客 338

FOC 转子初始位置检测(图文详解)

什么是转子的初始位置? 其实转子的初始位置是不确定的,但是在电机启动的时候,我们需要得到电角度,这样才可以进行矢量控制;所以,这里将转子与A轴重合作为初始位置,此时电角度也恰好为零,具体如下图所示; ) 至于原理下面会详细分析,这样在转子到初始位置后,也可以得到准确的电角度,就可以实现磁场和转子的同步转动。 如何让转子运行到初始位置? 其实这是一个很简单的问题,在这里我将它放大了,简单地分析了一...

一名热爱技术的工程师的博客。分享技术干货,记录美好生活。永远相信美好的事情即将发生。 2万+

杭电OJ——1051 Wooden Sticks

Wooden Sticks Problem Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in o

李树花开,风中摇曳 8344

热视觉2:使用Python和OpenCV从图像中测量温度

这篇博客将介绍学习热/中远红外视觉的基础知识,gray8 和 gray16 图像(即最常见的热成像格式)之间的差异,学习如何使用Python和OpenCV从热图像中的每个像素点测量温度,并以不同的调色板显示结果。以及如何实时计算视频流和UVC热像仪的每个像素温度。

qq_40985985的博客 6719

贪心算法H题

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare processing a sti.

qq_50960478的博客 502

Office系列完全干净卸载工具合集(最全)

使用 Microsoft Fix it 卸载 Microsoft Office 套件 一、Windows 7、Windows Vista或Windows XP下卸载Office 1.MicrosoftEasyFix50416 工具用来卸载office 2003 MicrosoftEasyFix50416_Office2003.msi 2.MicrosoftEasyFix50154 工具用来卸载office 2007 MicrosoftEasyFix50154_Office2007.msi 3.Microso

业精于勤,荒于嬉 3万+

学Simulink——基于直流电机的建模与控制场景实例:直流电机带负载突变时的动态响应仿真

在实际应用中,直流电机经常需要应对各种工作条件的变化,例如负载突变。了解电机在这种情况下的动态响应特性对于确保系统的稳定性和可靠性至关重要。通过仿真分析,可以预测电机在不同负载条件下的表现,并优化控制系统的设计。本文将详细介绍如何使用来构建一个直流电机带负载突变时的动态响应仿真模型,并通过仿真展示其应用效果。本文介绍了如何使用构建一个直流电机带负载突变时的动态响应仿真模型,并通过仿真展示了其应用效果。

xiaoheshang_123的博客 119

题解:Wooden Sticks(贪心)

There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called ...

晚安( ̄o ̄) . z Z 957

修复Oracle MySQL Server 安全漏洞(CVE-2023-0464)

修复Oracle MySQL Server 安全漏洞(CVE-2023-0464)

路~可以走过 3694

zoj 1025 wooden sticks

<br />  这题是大黄dp分类里边的..想了好久..刚开始想的是,先把一个排序,然后每次按照第二个未排序的元素进行最长上升子序列的查找..一次查找一个,记录下路径..然后数出一共有多少个路径..但是之后发现这种方法好像不可取..因为这一次删掉的最长上升序列并不一定能满足使下一个最长(如果要想实现的话,还有点麻烦..)  最后发现其实在第一个元素排好序之后只需找出按照第二个元素的最长不上升子序列的长度就行..<br />因为第一个元素完全满足条件的情况下..第二个元素的最长不上升子序列的长度就一定是所需要

个人信息备份站。。 659

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

zoj 1025 Wooden Sticks

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25   引用cc98 watashi 大牛的话: 其实题目的意思就是把所有元素分为最少的堆数,每堆有l可以证明不下降序列完全覆盖数就是最长下降子列的长度(记为L): 显然覆盖数不能比L小,否则由抽屉原理,必然有下降子列中两元素(a 于是先将数列按照l,w的

/0 1330

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

ZOJ1025 Wooden Sticks

题目:Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs som

_今已亭亭如盖矣 885

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

ZOJ1025-Wooden Sticks 加工木棒问题

ZOJ1025-Wooden Sticks 加工木棒问题 【问题描述】 现有n根木棒,已知它们的长度和重量。要用一部木工机一根一根地加工这些木棒。该机器在加工过程中需要一定的准备时间用于清洗机器、调整工具和模板。 木工机需要的准备时间如下: (1) 第一根木棒需要1min的准备时间; (2) 在加工了一根长为l,重为w的木棒后,接着加工一根长为l’(l≤l’), 重为w’(w≤...

sinat_38432876的博客 597

ZOJ 1025:Wooden Sticks

Wooden Sticks Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a

小坏蛋_千千 583

ZOJ - 1025 Wooden Sticks 【贪心】

Description There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some...

一定要站在自己热爱的生活里闪闪发光 3万+

ZOJ 1025 Wooden Sticks

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:锯木桩,每次小于前面开过机的长和厚不用建立,大于的话就得重新发动,发动时间为1,为求最小发动世界。 先快排(从大到小),在求下降子序列。 先快排(从小到大),再求有几个连续上升子序列,下面代码按这种做法做 代码: #inclu

老子(道家) 555

ZOJ1025-Wooden Sticks

#include <iostream> #include <stdio.h> #include <memory.h> #include <algorithm> using namespace std; #define maxN 5001 struct stick { int l; int w; }; int DP(int n...

zjutsunny的博客 165

【算法】ZOJ1025-Wooden Sticks

描述 现有n根木棒,已知它们的长度和重量。要用一部木工机一根一根地加工这些木棒。该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模版的。 木工机需要的准备时间如下: (1)第一根木棒需要1min的准备时间; (2)在加工了一根长为l ,重为w的木棒之后,接着加工一根长为l ’ (l ≤ l’ ),重为 w’ ( w≤w’)的木棒是不需要任何准备时间的,否则需要一分钟的准备时间。 给...

SuperSources的博客 464

[ZOJ - 1025] Wooden Sticks (贪心)

链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1025 题意 给你nnn个(l,w)(l,w)(l,w),你排列它们,你尽可能地想使得li−1&lt;=li and wi−1&lt;=wil_{i-1}&lt;=l_i\ and\ w_{i-1}&lt;=w_ili...

梧桐 256
上一篇: Hdu 1079 Calendar Game
下一篇: 三角形
Magic_____
博客等级 码龄14年 11粉丝 160原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址