Wooden Sticks

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

Total Submission(s): 12157    Accepted Submission(s): 5036

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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct st
{
int l,w;
}data[10050];
int cmp(st a,st b) //按木头长度从长到短排序。若长度一样则按质量从大到小排序。
{
if(a.l!=b.l)
return a.l>b.l;
else
return a.w>b.w;
}
int a[10050];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,j,n,k,sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d",&data[i].l,&data[i].w);
}
sort(data,data+n,cmp);
memset(a,0,sizeof(a));
for(i=0;i<n;i++) //将遍历过的且满足条件的木头做标记,用sum统计所须要的次数。
{
if(a[i])continue;
k=data[i].w;
for(j=i+1;j<n;j++)
{
if(k>=data[j].w&&!a[j])
{
k=data[j].w;
a[j]=1;
}
}
sum++;
}
printf("%d\n",sum);
}
}

	

Wooden Sticks(杭州电1051)的更多相关文章

  1. 杭电 1051 Wooden Sticks

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

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

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

  3. HDU 1051 Wooden Sticks (贪心)

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

  4. HDOJ.1051 Wooden Sticks (贪心)

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

  5. HDU ACM 1051/ POJ 1065 Wooden Sticks

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

  6. 1051 Wooden Sticks

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

  7. HDU 1051:Wooden Sticks

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

  8. HDU 1051 Wooden Sticks 贪心||DP

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

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

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

随机推荐

  1. 将n进制的数组压缩成字符串(0-9 a-z)同一时候解压

    比如一个3进制的数组: [1 1 2 2 2 0 0] 用一个字符串表示... 此类题目要明白两点: 1. 打表:用数组下标索引字符.同一时候注意假设从字符相应回数字: int index = (st ...

  2. 积累的VC编程小技巧之对话框

    1.用鼠标移动基于对话框的无标题栏程序的简单方法 void CVCTestDlg::OnLButtonDown(UINT nFlags, CPoint point) {    //一句话解决问题    ...

  3. Java原型模式之基础

    一.是什么? 定义:用原型实例指定创建对象的种类,而且通过拷贝这些原型创建新的对象.(官方定义) 原型模式主要用于对象的复制,它的核心是就是类图中的原型类Prototype. Prototype类须要 ...

  4. eclipse Maven构建的project无法公布lib到tomcat的解决方法

    问题: eclipse导入基于Maven的web项目时,公布到tomcat中.发现lib文件夹及jar包没有公布过去. 解决方式: eclipse中,选择项目属性Properties --> D ...

  5. 类型自动转换引起的误解——QString可以赋值数字1,也能直接与0比较,真是昏倒!

    看以下代码,能编译通过: void MainWindow::on_pushButton_clicked() { QString str = "test"; ) { QMessage ...

  6. WebBrowser控件禁用超链接转向、脚本错误提示、默认右键菜单和快捷键

    原文:WebBrowser控件禁用超链接转向.脚本错误提示.默认右键菜单和快捷键 WebBrowser控件禁用超链接转向.脚本错误提示.默认右键菜单和快捷键从 VS2005开始,VS自带的 WebBr ...

  7. hdu1116--解题报告--初步了解欧拉回路

    由题目意思..我们只要把n个字符串的首尾字母看作是点,这个字符串看着边来处理就可以啦...将题目的案例图形化如下: 那么接着就是欧拉路径和欧拉回路判断,我们这里用并査集来判断图是不是连通的,然后根据有 ...

  8. OpenCV HaarTraining代码解析(二)cvCreateMTStumpClassifier(建立决策树)

    HaarTraining关键的部分是建立基分类器classifier,OpenCV中所採用的是CART(决策树的一种):通过调用cvCreateMTStumpClassifier来完毕. 这里我讨论利 ...

  9. ZooKeeper安装与运行

    ZooKeeper安装与运行 首先从官网下载ZooKeeper压缩包,然后解压下载得到的ZooKeeper压缩包,发现有“bin,conf,lib”等目录.“bin目录”中存放有运行脚本:“conf目 ...

  10. hdu4908(中位数)

    传送门:BestCoder Sequence 题意:给一个序列,里面是1-N的排列,给出m,问以m为中位数的奇数长度的序列个数. 分析:先找出m的位置,再记录左边比m大的状态,记录右边比m大的状态,使 ...