Wooden Sticks

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Submit Status Practice _

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 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

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)的更多相关文章

  1. HDU1051 Wooden Sticks 【贪婪】

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  2. HDU1051:Wooden Sticks

    Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...

  3. 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 ...

  4. hdu1051 Wooden Sticks(贪心+排序,逻辑)

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)

    嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...

  6. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  7. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  8. HDU ACM 1051/ POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. 1051 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

随机推荐

  1. Centos7.x系统优化

    1.安装常用软件 yum install tree nmap sysstat lrzsz dos2unix wget  net-tools ntpdate -y 2.配置yum源 mv /etc/yu ...

  2. Linux内核实践之工作队列

    工作队列(work queue)是另外一种将工作推后执行的形式,它和tasklet有所不同.工作队列可以把工作推后,交由一个内核线程去执行,也就是说,这个下半部分可以在进程上下文中执行.这样,通过工作 ...

  3. WO+开放平台:API调用开发手记(话费计费接口2.0)

    WO+能力共享平台(http://open.wo.com.cn)是中国联通推出的开放平台.拥有的丰富电信能力资源以及深度整合挖掘的第三方能力资源等.WO+平台提供的API均为简洁优雅的RESTful风 ...

  4. Java取得操作系统的临时目录

    一般来说,程序员用Eclipse在Windows上编程,而会将war/ear包发布到Linux的服务器上. 涉及临时文件输出的话需要找一个临时目录,下面的语句就能帮你获得不分操作系统的临时目录 Str ...

  5. Binder与Servicede关联

    Binder是Android上IPC的基础和关键.那么在使用过程中,大多数时候看到的是client与server的结构,即Server通过创建服务来向Client提供服务,Client则通过绑定到Bi ...

  6. JAVA Eclipse中如何简易的实现消息机制

    大部分情况下,我们需要实现的消息机制无非是某个类得到了数据,需要传递到某个主界面上去显示,可以把这个消息在类中做成全局变量,主界面的类用一个线程定时扫描,如果这个数据不是空,则说明被类刷新了,那么更新 ...

  7. ionic准备之angular基础——run方法(4)

    可以看到整个angular.module对象具有以下各种属性和方法 <!DOCTYPE html> <html lang="en"> <head> ...

  8. javascript 模块引擎 (手写草稿)

    1.试题: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  9. 【BIEE】10_资料库查看数据报错

    导入元数据后,在资料库右键物理表名,[查看数据]报错: 出现这个问题,没搞明白是为啥- 后来百度意外发现一个方法,修改NQSConfig.INI文件即可解决问题 那么就开始来搞定这个问题 [1]打开路 ...

  10. 【Java】Java_19递归算法

    1.递归算法 A方法调用B方法,我们很容易理解!递归就是:A方法调用A方法!就是自己调用自己,因此我们在设计递归算法时,一定要指明什么时候自己不调用自己.否则,就是个死循环! 1.1递归算法要点 递归 ...