Wooden Sticks
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20938   Accepted: 8872

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 ( 9 , 4 ) , ( 2 , 5 ) , ( 1 , 2 ) , ( 5 , 3 ) ,
and ( 4 , 1 ) , then the minimum setup time should be 2 minutes since
there is a sequence of pairs ( 4 , 1 ) , ( 5 , 3 ) , ( 9 , 4 ) , ( 1
, 2 ) , ( 2 , 5 ) .

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 2n 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

不知道为何要分到最长上升子序列..只有上升的感觉吧。。
题意:n根木棒,每根木棒都有个长度和重量两个属性,现在要处理这些木棒,当下一根木棒的重量和长度都不小于上一根木棒时,机器就继续工作,否则,机器就要一秒钟重置,
问全部处理完要多久.
题解:和矩形嵌套问题几乎一样,只是这里需要处理完所有木棒.先按长度排序,如果长度相同再按重量排序。利用贪心思想,每次找到可以延伸到的最远距离。然后把这条路上的点全部标记,然后从没标记的下一点开始找,一直找到可以延伸的最远距离。每次重新找+1就是了。
#include<iostream>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;
const int N = ; struct Wooden{
int l,w;
}wd[N];
int cmp(Wooden a ,Wooden b){
if(a.l!=b.l) return a.l<b.l;
return a.w<b.w;
}
bool use[N];
int main()
{
int tcase ;
scanf("%d",&tcase);
while(tcase--){
memset(use,,sizeof(use));
int n;
scanf("%d",&n);
int time = ;
for(int i=;i<=n;i++) scanf("%d%d",&wd[i].l,&wd[i].w);
sort(wd+,wd++n,cmp);
for(int i=;i<=n;i++){
if(!use[i]){
++time;
int w = wd[i].w;
for(int j=i+;j<=n;j++){
if(!use[j]&&wd[j].w>=w){
w = wd[j].w;
use[j]=;
}
}
}
}
printf("%d\n",time);
}
return ;
}

hdu 1065(贪心)的更多相关文章

  1. Hdu 5289-Assignment 贪心,ST表

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=5289 Assignment Time Limit: 4000/2000 MS (Java/Others) ...

  2. hdu 4803 贪心/思维题

    http://acm.hdu.edu.cn/showproblem.php?pid=4803 话说C++还卡精度么?  G++  AC  C++ WA 我自己的贪心策略错了 -- 就是尽量下键,然后上 ...

  3. hdu 1735(贪心) 统计字数

    戳我穿越:http://acm.hdu.edu.cn/showproblem.php?pid=1735 对于贪心,二分,枚举等基础一定要掌握的很牢,要一步一个脚印走踏实 这是道贪心的题目,要有贪心的意 ...

  4. hdu 4974 贪心

    http://acm.hdu.edu.cn/showproblem.php?pid=4974 n个人进行选秀,有一个人做裁判,每次有两人进行对决,裁判可以选择为两人打分,可以同时加上1分,或者单独为一 ...

  5. hdu 4982 贪心构造序列

    http://acm.hdu.edu.cn/showproblem.php?pid=4982 给定n和k,求一个包含k个不相同正整数的集合,要求元素之和为n,并且其中k-1的元素的和为完全平方数 枚举 ...

  6. HDU 2307 贪心之活动安排问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2037 今年暑假不AC Time Limit: 2000/1000 MS (Java/Others)  ...

  7. HDU 1052 贪心+dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1052 Tian Ji -- The Horse Racing Time Limit: 2000/1000 MS ...

  8. HDU 2111 Saving HDU【贪心】

    解题思路:排序后贪心,和fatmouse's  trade 类似 Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: ...

  9. HDU 2831 (贪心)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2831 题目大意:植物大战僵尸.给定种植植物时间间隔t,以及每个僵尸的到达时间v,生命d.问是否能赢. ...

随机推荐

  1. 除了love和hate,还能怎么表达那些年的“爱恨情仇”?

    实用英语 帮你全面提高英语水平 关注 童鞋们每次刷美剧的时候,相信都会被CP感满满的男女主角虐得体无完肤吧. 可是,一到我们自己表达爱意或者恨意的时候,却苦于词穷,只会用love, like, hat ...

  2. Linux之socket套接字编程20160704

    介绍套接字之前,我们先看一下传输层的协议TCP与UDP: TCP协议与UDP协议的区别 首先咱们弄清楚,TCP协议和UCP协议与TCP/IP协议的联系,很多人犯糊涂了,一直都是说TCP/IP协议与UD ...

  3. Codeforces Round #508 (Div. 2) E. Maximum Matching(欧拉路径)

     E. Maximum Matching 题目链接:https://codeforces.com/contest/1038/problem/E 题意: 给出n个项链,每条项链左边和右边都有一种颜色(范 ...

  4. 题解【bzoj2427 [HAOI2010]软件安装】

    Description 现在我们的手头有\(N\)个软件,对于一个软件\(i\),它要占用\(W_i\)的磁盘空间,它的价值为\(V_i\).我们希望从中选择一些软件安装到一台磁盘容量为\(M\)计算 ...

  5. 第三方库升级Nginx

    通过PPA方式,来升级Nginx 1. 添加PPA sudo add-apt-repository ppa:nginx/stable sudo apt-get updatesudo apt-get u ...

  6. ZOJ 3556 How Many Sets I

    How Many Sets I Time Limit: 2 Seconds      Memory Limit: 65536 KB Give a set S, |S| = n, then how ma ...

  7. vijos 1426 背包+hash

    背景 北京奥运会开幕了,这是中国人的骄傲和自豪,中国健儿在运动场上已经创造了一个又一个辉煌,super pig也不例外……………… 描述 虽然兴奋剂是奥运会及其他重要比赛的禁药,是禁止服用的.但是运动 ...

  8. 【GDKOI2016Day1T1-魔卡少女】【拆位】线段树维护区间内所有连续子区间的异或和

    题意:给出N个数,M个操作.操作有修改和询问两种,每次修改将一个数改成另一个数,每次询问一个区间的所有连续子区间的异或和.n,m<=100000,ai<=1000 题解: 当年(其实也就是 ...

  9. 【lydsy1407】拓展欧几里得求解不定方程+同余方程

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1407 题意: 有n个野人,野人各自住在第c[i]个山洞中(山洞成环状),每年向前走p[i] ...

  10. 【BZOJ1598】牛跑步 [A*搜索]

    牛跑步 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description BESSIE准备用从牛棚跑到池塘的方 ...