HDU 1005 Wooden Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1051
(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).
#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N; struct Node {
int l;
int w;
int flag;
}node[maxn]; bool cmp(const Node& a, const Node& b) {
return a.l == b.l ? a.w < b.w : a.l < b.l;
} int main() {
int T;
scanf("%d", &T);
while(T --) {
memset(node, 0, sizeof(node));
scanf("%d", &N);
for(int i = 1; i <= N; i ++) {
scanf("%d%d", &node[i].l, &node[i].w);
node[i].flag = 0;
} int cnt = 0;
sort(node + 1, node + 1 + N, cmp);
for (int k = 1; k <= N;)
{
cnt ++;
int L = 0, W = 0;
for (int i = 1; i <= N; i ++) {
if (!node[i].flag)
if (node[i].l >= L && node[i].w >= W) {
node[i].flag = 1;
L = node[i].l;
W = node[i].w;
k ++;
}
}
}
printf("%d\n", cnt);
}
return 0;
}
HDU 1005 Wooden Sticks的更多相关文章
- HDU 1051 Wooden Sticks (贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1051 Wooden Sticks 贪心||DP
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU - 1051 Wooden Sticks 贪心 动态规划
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1051:Wooden Sticks(水题,贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU 1051 Wooden Sticks
题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1 ...
- HDU 1051 Wooden Sticks【LIS】
题意:给出n个木头的重量wi,长度li,如果满足w[i+1]>=w[i]且l[i+1]>=l[i],则不用耗费另外的加工时间,问至少需要多长时间加工完这些木头. 第一次做这一题目也没有做出 ...
- HDU 1051 Wooden Sticks 造木棍【贪心】
题目链接>>> 转载于:https://www.cnblogs.com/Action-/archive/2012/07/03/2574800.html 题目大意: 给n根木棍的长度 ...
- HDU 1051 Wooden Sticks 贪心题解
本题一看就知道是最长不减序列了,一想就以为是使用dp攻克了. 只是那是个错误的思路. 我就动了半天没动出来.然后看了看别人是能够使用dp的,只是那个比較难证明其正确性,而其速度也不快.故此并非非常好的 ...
- hdu 1051 wooden sticks (贪心+巧妙转化)
#include <iostream>#include<stdio.h>#include<cmath>#include<algorithm>using ...
随机推荐
- 2018 Wannafly summer camp Day2--New Game!
New Game! 描述 题目描述: Eagle Jump公司正在开发一款新的游戏.泷本一二三作为其员工,获得了提前试玩的机会.现在她正在试图通过一个迷宫. 这个迷宫有一些特点.为了方便描述,我们对这 ...
- 全局变量重复定义,fatal error LNK1169: 找到一个或多个多重定义的符号
1.在GlobeValue.h中定义了一个变量: char gl_UID[256]; 2.在b.cpp和e.cpp中分别引用GlobeValue.h,并且使用gl_UID的全局变量, 结果出现:fat ...
- ABAP术语-Error Message
Error Message 原文:http://www.cnblogs.com/qiangsheng/archive/2008/01/30/1058283.html Information from ...
- shell编程基础进阶
为什么学习shell编程 shell脚本语言是实现linux/unix 系统管理机自动化运维所必备的重要工具,linux/unix系统的底层及基础应用软件的核心大部分涉及shell脚本的内容.每一个合 ...
- jquery图片滚动demo.css
body, html { font-size: 100%; padding: 0; margin: 0;} /* Reset */*,*:after,*:before { -webkit-box-si ...
- pyqt4学习资料
官方文档: http://pyqt.sourceforge.net/Docs/PyQt4/classes.html 啄木鸟社区:https://wiki.woodpecker.org.cn/moin/ ...
- 用状态机表示SFC中的并行分支
过去一直认为,状态机表示SFC会不会是任务复杂化,这次简单实验了一下,感觉还可以.请看下面的控制. 在SFC中,A和B是一对并行分支,汇合后转移到C分支中,怎么了用状态机表示呢?这里我们在状态机里分别 ...
- python3 练习题100例 (二十四)打印完数
完数:一个数如果恰好等于它的因子之和,这个数就称为"完数".例如 6 = 1+2+3. 题目内容: 输入一个正整数n(n<1000),输出1到n之间的所有完数(包括n). 输 ...
- 网站安全检测 漏洞检测 对thinkphp通杀漏洞利用与修复建议
thinkphp在国内来说,很多站长以及平台都在使用这套开源的系统来建站,为什么会这么深受大家的喜欢,第一开源,便捷,高效,生成静态化html,第二框架性的易于开发php架构,很多第三方的插件以及第三 ...
- 插头DP(基于连通性状态压缩的动态规划问题)(让你从入门到绝望)
今天,我,Monkey king 又为大家带来大(ju)佬(ruo)的算法啦!--插头DP 例题(菜OJ上的网址:http://caioj.cn/problem.php?id=1489): 那么,这道 ...