Wooden Sticks

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12443    Accepted Submission(s): 5167

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

 #include<iostream>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct ln{
int x;
int y;
int z;
}a[];
bool cmp(const ln a,const ln b)
{
if(a.y==b.y)
return a.x<b.x;
else
return a.y<b.y;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].z=;
}
sort(a,a+n,cmp);
int count=,length;
for(int i=;i<n;i++)
{
if(!a[i].z)
{
count++;
length=a[i].x;
for(int j=i+;j<n;j++)
{
if(!a[j].z)
{
if(a[j].x>=length)
{
a[j].z=;
length=a[j].x;
}
} }
} }
printf("%d\n",count);
}
return ;
}
 

1051 Wooden Sticks的更多相关文章

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

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

  2. HDU 1051 Wooden Sticks (贪心)

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

  3. HDOJ.1051 Wooden Sticks (贪心)

    Wooden Sticks 点我挑战题目 题意分析 给出T组数据,每组数据有n对数,分别代表每个木棍的长度l和重量w.第一个木棍加工需要1min的准备准备时间,对于刚刚经加工过的木棍,如果接下来的木棍 ...

  4. HDU 1051 Wooden Sticks 贪心||DP

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

  5. HDU - 1051 Wooden Sticks 贪心 动态规划

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

  6. hdu 1051:Wooden Sticks(水题,贪心)

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

  7. 杭电 1051 Wooden Sticks

    Description There is a pile of n wooden sticks. The length and weight of each stick are known in adv ...

  8. HDOJ 1051. Wooden Sticks

    题目 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The ...

  9. HDU 1051 Wooden Sticks

    题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1 ...

随机推荐

  1. VC 2010下安装OpenCV2.4.4

    说明: 安装平台:32位XP,VS2010: OpenCV 2.4.4不支持VC 6.0: 网上有很多用CMake编译OpenCV的安装教程,这里建议先不要自己编译,如果使用预编译好的库有问题,再尝试 ...

  2. WP开发笔记——阻止Back后退键

    WP7中如何阻止Back后退键的后退事件呢? WP7上提供了物理的Back按键,获取Back物理键按下可以通过PhoneApplicationPage的BackKeyPress事件. 具体实现方法如下 ...

  3. WP开发笔记——程序的退出方法

    Windows Phone程序中,并没有之前的类似于“App.Exit()”之类的函数用来让你退出程序.这是怎么回事儿呢? 很简单,在Windows Phone 7中系统要求配备了硬件的“Back”键 ...

  4. Linux下的vi编辑器与gcc工具的使用

    最近在网上找了些视频,自学了一点Linux环境下,C编程的方法. 注 vi与vim是有区别的,vim打开的源码文件其中的关键字是有颜色的. vi编辑器有3种模式,命令行模式,插入模式,底行模式. 如果 ...

  5. Window 8.1 计时器功能及图片切换

    <Canvas Margin="450,0" Width="795" Grid.Column="1"> <Image Ma ...

  6. Android 多国语言

    参考android 开发文档,  ISO 639-1  ISO 3166-1-alpha-2 关于中国的: 中国其他地区: https://en.wikipedia.org/wiki/ISO_3166 ...

  7. c#配置log4net步骤

    1.引入添加log4net.dll引用 2.建立配置文件Log4Net.config(名字自定义).文件内容参考,输出的文件名称可更改 .运行是要放入到相应bin/debug(release) 目录 ...

  8. JS去除数组中重复值的四种方法

    JS去除数组中重复值的四种方法 1 /// <summary>            o[this[i]] = "";  }      }       newArr.p ...

  9. Boost的自动链接功能

    Boost是一个强大的C++第三方库,但是Boost的各种问题实在是很让人蛋疼.我搜到过一篇文章关于LuaBind使用Boost Build管理工具来管理源代码以及编译的博文,其第一句话就是Fuck ...

  10. 【nodejs】jade模板入门

    使用jetbrians webstom创建空项目 1.创建package.json 引用依赖配置 { "name": "demojade", "des ...