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. Java:网络编程之应用实例

    1.聊天 编写一个聊天程序,有收数据的部分和发数据的部分. 这两部分需要同时执行,那么就需要多线程技术. 一个线程控制发送. 一个线程控制接收. 因为收和发动作是不一致的,所以要定义两个run方法,而 ...

  2. domino数据同步到sql server

          近期有个需求,要同步domino数据到selservlet数据库,查看几年前ls使用odbc写的同步功能,还能正常使用.而且加入读者域进去功能(之前没有这个需求).改进成网页配置版本号(曾 ...

  3. Python - 连续替换(replace)的正則表達式(re)

    字符串连续替换, 能够连续使用replace, 也能够使用正則表達式. 正則表達式, 通过字典的样式, key为待替换, value为替换成, 进行一次替换就可以. 代码 # -*- coding: ...

  4. sql取随机结果集

    应用场景: 某日,接产品姐姐需求,网站搜索页在搜索特定的内容时候,会现实搜索不到结果!如衣服网站,搜索鞋子等.为了不直接呈现一个赤裸裸的无此商品页面,so,需要在搜索商品件数小于3时,在下面随机推荐本 ...

  5. jquery给多个span赋值

    因为我想在页面载入完毕后,有几个地方显示当前时间,所以我须要给多个span赋值. span代码的写法例如以下: <span name="currentDate">< ...

  6. Java模式的秘密--java常用的几种模式

    要学习设计模式,首先要明白设计模式,就是为实现某一种或某一组功能提供的代码编码方式.它没有固定的套路,只有约定俗成的风格.所有编码者可以根据已有的设计模式开放思维,设计出自己的设计模式,也会在无意中使 ...

  7. python中ascii码和字符的转换

    将ASCII字符转换为对应的数值即‘a’-->65,使用ord函数,ord('a') 反正,使用chr函数,将数值转换为对应的ASCII字符,chr(65)

  8. Angular 学习笔记——filter

    <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <met ...

  9. Python 实现指定目录下 删除指定大小的文件

    import os, sys from stat import * BIG_FILE_THRESHOLD = 6000L #1000000L dict1 = {} # dict2 = {} # def ...

  10. 性能测试之Tomcat优化

    1.Tomcat最大连接数等配置   Tomcat的server.xml中Context元素的以下参数都是什么意思? <Connector port="8080"maxThr ...