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 <iostream>
#include <algorithm>
#include <cstring>
using namespace std; int mark[]; struct node
{
int a;
int b;
} data[]; bool cmp(const node &a,const node &b)
{
if(a.a>b.a)
return true;
if(a.a==b.a)
{
if(a.b>b.b)
return true;
else return false;
}
if(a.a<b.a)
return false;
} int main()
{
int t,n,ans,m;
cin>>t;
while(t--)
{
cin>>n;
memset(mark,,sizeof(mark));
ans=;
for(int i=;i<n;i++)
cin>>data[i].a>>data[i].b;
sort(data,data+n,cmp);
//for(int i=0;i<n;i++)
//cout<<data[i].a<<" "<<data[i].b<<endl;
for(int i=;i<n;i++)
{
if(mark[i]==)
{
ans++;
m=i;
for(int j=i+;j<n;j++)
{
if(data[m].b>=data[j].b&&mark[j]!=)
{
mark[j]=;
m=j;
}
}
} }
cout<<ans<<endl; }
return ;
}

HDU1051:Wooden Sticks的更多相关文章

  1. HDU 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. HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)

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

  4. HDU1051 Wooden Sticks 【贪婪】

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

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

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

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

  7. Wooden Sticks(hdu1051)

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

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

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

  9. Wooden Sticks

    Wooden Sticks Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

随机推荐

  1. CMA-连续内存分配

    CMA: Contignous Memory Allocator,连续内存分配,一般是分配给Camera,HDMI等使用,避免预留大块内存 1.声明连续内存 使用dma_contignous_rese ...

  2. win10系统 L2TP连接尝试失败:ERROR因为安全层在初始化与远程计算机的协商时遇到了一个处理错误

    1 确保IPsec Policy Agent服务已启动 2 确保路由和远程访问(Routing and Remote Access)和远程访问连接管理器服务(Remote Access Connect ...

  3. srping标签和hibernate查询

    Spring的注解形式:@Repository.@Service.@Controller,它们分别对应存储层Bean,业务层Bean,和展示层Bean. view层:    结合control层,显示 ...

  4. 【MySQL】filesort.cc 源代码阅读笔记

    最近阅读了部分MySQL排序的代码,把心得记录一下. 参考代码 MySQL: 文件: filesort.cc 函数: filesort() 排序过程伪代码 function filesort(tabl ...

  5. hdu 1531 King

    首先吐槽一下这个题目的题意描述,我看了半天才明白. 下标全部都是乱标的!!!!出题者能不能规范一点下标的写法!!!! 差分约束系统 #include<cstdio> #include< ...

  6. CSS3秘笈复习:第七章

    1.边距冲突: 当元素的bottom margin碰到另一个元素的top margin可能会产生一些怪异的计算,浏览器会忽略小的那个值而使用大的值. 2.边距折叠: 假设要在警告框里插入一个标题,并且 ...

  7. POJ 2234 Matches Game(取火柴博弈1)

    传送门 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  8. Java 序列化 transient关键字

    Java 序列化 transient关键字 @author 敏敏Alexia 转自:http://www.cnblogs.com/lanxuezaipiao/p/3369962.html 1. tra ...

  9. 【转】Storm并行度详解

    1.Storm并行度相关的概念 Storm集群有很多节点,按照类型分为nimbus(主节点).supervisor(从节点),在conf/storm.yaml中配置了一个supervisor,有多个槽 ...

  10. delphi怎么实现全选的功能

    1. SelectAll 可以实现全选功能 Delphi/Pascal code edit1.SelectAll; // Delphi/Pascal code RichEdit1.SelStart:= ...