Wooden Sticks(hdu1051)
Wooden Sticks
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
(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
Output
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
Sample Output
2 1 3
//第一行是代表测试数据t
每组数据第一行是一个整数 n ,代表木头的数量
然后 n 对数据 代表 木头的长度,和重量
需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的时间,如果第i+1个木棒的重量和长度都大于等于
第i个处理的木棒,那么将不会耗费时间,否则需要消耗一个单位的时间。
问最短时间
//贪心解决了
排个序,就行
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std; struct Node
{
int l,w;
}node[],setup[]; bool cmp(Node a,Node b)
{
if (a.l==b.l)
return a.w<b.w;
return a.l<b.l;
} int main()
{
int t;
cin>>t;
while (t--)
{
int n;
int i,j;
cin>>n;
for (i=;i<n;i++)
{
cin>>node[i].l>>node[i].w;
}
sort(node,node+n,cmp);
int ans=;
setup[].l=node[].l;
setup[].w=node[].w; for (i=;i<n;i++)
{
int ok=;
for (j=;j<ans;j++)
{
if (setup[j].l<=node[i].l&&setup[j].w<=node[i].w)
{
setup[j].l=node[i].l;
setup[j].w=node[i].w;
ok=;
break;
}
}
if (ok==)
{
setup[ans].l=node[i].l;
setup[ans].w=node[i].w;
ans++;
}
}
cout<<ans<<endl;
}
return ;
}
Wooden Sticks(hdu1051)的更多相关文章
- HDU1051 Wooden Sticks 【贪婪】
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU1051:Wooden Sticks
Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...
- Hdu1051 Wooden Sticks 2017-03-11 23:30 62人阅读 评论(0) 收藏
Wooden Sticks Problem Description There is a pile of n wooden sticks. The length and weight of each ...
- hdu1051 Wooden Sticks(贪心+排序,逻辑)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)
嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- HDU ACM 1051/ POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 1051 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
随机推荐
- 路由器漏洞复现分析第二弹:CNVD-2018-01084
1月17日,CNVD公开了D-LinkDIR 615/645/815 service.cgi远程命令执行漏洞(CNVD-2018-01084),freebuf上有前辈写了一篇漏洞复现和poc的文章(h ...
- ZeroMQ使用学习记录(转)
ZMQ简介 ZMQ(ØMQ.ZeroMQ, 0MQ)看起来像是一套嵌入式的网络链接库,但工作起来更像是一个并发式的框架.它提供的套接字可以在多种协议中传输消息,如线程间.进程间.TCP.广播等.你可以 ...
- 机器学习第1课:引言(Introduction)
1.前言 Machine Learning(机器学习)是研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能. 它是人工智能的核心,是使计算机具有 ...
- Nigix加入Hello World模块
详细资料:<深入理解Nginx> 1.编写第三方模块 建立文件夹hello,里面有两个文件: ngx_http_mytest_module.c #include <ngx_confi ...
- 《Android源代码设计模式解析与实战》读书笔记
1.定义 将对象组合成树形结构以表示"部分-总体"的层次结构,使得用户对单个对象和组合对象的使用具有一致性. 2.使用场景 (1)表示对象的部分-总体层次结构时. (2)从一个总体 ...
- 【Excle】如何隐藏数据透视表中的错误值
如下:数据透视表出现错误 怎么解决呢 步骤 方法① 单击数据透视表任意单元格→数据透视表工具→分析→选项→勾选"对于错误值显示"→确定 方法② 右键→数据透视表选项(同样可以修改)
- 那些奇妙的"大师"是怎样炼成的(科学、迷信、心理)
近期王林大师从神坛上掉下来直接掉进了监狱,有关他的非常多神话也相同被撕下了. 事实上这类奇妙的大师在地球上非常多,美国的非常多"邪教"头目,国内的邪教头目都属于这一类.国内比較轰动 ...
- &&与&符号区别
http://topic.csdn.net/u/20080915/16/f5125300-f69f-4da8-9c3a-a7458590553f.html && 与 &区别: ...
- view无限旋转
- (void) showRefreshAnimation { [UIView animateWithDuration: options:UIViewAnimationOptionCurveLinea ...
- Jenkins Docker 插件
原文地址:https://wiki.jenkins.io/display/JENKINS/Docker+Plugin Created by magnayn -, last modified by Ni ...