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. bzoj1690:[Usaco2007 Dec]奶牛的旅行(分数规划+spfa判负环)

    PS:此题数组名皆引用:戳我 题目大意:有n个点m条有向边的图,边上有花费,点上有收益,点可以多次经过,但是收益不叠加,边也可以多次经过,但是费用叠加.求一个环使得收益和/花费和最大,输出这个比值. ...

  2. java AES 加密解密工具(Advanced Encryption Standard)发现明文相同但每次重启服务后密文就会不同于是有了改进

    1.通用方法 package com.qlkj.hzd.commom.utils; import javax.crypto.*; import java.io.UnsupportedEncodingE ...

  3. jquery 操作实例一

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  4. Linux 环境下用Tomcat 发布项目

    1.前提条件: a.安装远程连接Linux软件:F-Secure SSH File Transfer Trial[简写为:FSSH]: b.打开FSSH,远程连接Linux[单击“Quick Conn ...

  5. weakself的另一种写法

    在不久前看AFNetworking的源码时候发现了这么一句: 1 2 3 4 5 6 7 8 9 10 // 不知道这行代码的使用场景的同学你该去自习看看ARC的注意事项和Block的使用了 // A ...

  6. 2017 济南综合班 Day 1

    送分题(songfen) Time Limit:1000ms   Memory Limit:128MB 题目描述 LYK喜欢干一些有挑战的事,比如说求区间最大子段和.它知道这个题目有O(n)的做法.于 ...

  7. django中处理表单的经典流程

    def form_process_view(request): if request.method == 'POST': # 请求为 POST,利用用户提交的数据构造一个绑定了数据的表单 form = ...

  8. 【BZOJ】2054: 疯狂的馒头

    [题意]给定n个元素,m次给一段区间染色为i,求最终颜色. [算法]并查集 [题解]因为一个点只受最后一次染色影响,所以倒过来每次将染色区间用并查集合并,父亲指向最右边的点. 细节: 1.fa[n+1 ...

  9. linux 下用 c 实现 ls -l 命令

    #include <stdio.h> #include <sys/types.h> #include <dirent.h> #include <sys/sta ...

  10. Desert King(POJ2728+最优比率生成树+二分)

    题目链接:http://poj.org/problem?id=2728 题目: 题意:求一颗生成树,使得费用与距离的比值最小,其中距离等于两点之间的平面欧拉距离,费用为z坐标之差. 思路: 由上图我们 ...