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. MySQL导出csv乱码问题的解决

    csv乱码问题的解决      从MySQL导出数据到 csv 文件后,有时会发现用 excel 打开该导出 csv 文件显示的是乱码.这个问题是 csv 文件本身的文本编码问题导致的,解决办法: 1 ...

  2. Note_JavaWeb_SpringMVC_尚硅谷

    Spring MVC框架 官网文档 \spring-framework-4.2.6.RELEASE\docs\spring-framework-reference\htmlsingle ------- ...

  3. ThreadLocal 与 static 变量

    ThreadLocal是为解决多线程程序的并发问题而提出的,可以称之为线程局部变量.与一般的变量的区别在于,生命周期是在线程范围内的.static变量是的生命周期与类的使用周期相同,即只要类存在,那么 ...

  4. HDU-1757--A Simple Math Problem(矩阵乘法)

    Problem Description Lele now is thinking about a simple function f(x).If x < 10 f(x) = x.If x > ...

  5. 下载、安装jdk8(Windows下)并配置变量环境

    一.官网下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html 点击下图中的downloa ...

  6. ios 实现在tableViewCell上面添加长按手势 删除该条cell以及列表后台数据等

    自己的代码  需要   把属性更改成自己要使用的 //创建长按手势 在cellForRowAtIndexPath代理方法中 UILongPressGestureRecognizer *longPres ...

  7. 常用的HTTP状态码如下

    成功的状态码: – 服务器成功返回网页 – 未修改 失败的状态码: – 请求的网页不存在 – 服务器暂时不可用 – 服务器内部错误 下面的不是很常用,记住上面那几个就ok了,有bug了再补充 其他的状 ...

  8. Java中的Math类的简单实用

    System.out.println(Math.PI);//获取PI的值 System.out.println(Math.E);//常量E int min = Math.min(5, 4);//求最小 ...

  9. jQuery插件实现左右无缝轮播

    前段时间学习jQuery的时候,在网上找了个SuperSlide插件,做轮播图demo,感觉对于新人而言,还是挺容易上手的,代码量也少. 直接贴代码吧. 1.HTML <!DOCTYPE htm ...

  10. 推荐一篇很好的介绍wpf dependency property的文章

    http://www.codeproject.com/Articles/140620/WPF-Tutorial-Dependency-Property