Wooden Sticks

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
 
Source

 

————————————————————————————————————

题目的意思是给出若干个物品的长度和质量,调整机器需要1分钟,加工时如果下一件物品质量和长度都比上一件大或相等,那么不用重新调整,否则重新调整,问最少时间

思路:贪心,按长度或质量从小到大排序,依次取,找出递增子序列个数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include<vector>
#include <map>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long struct node{
int a,b,flag;
}p[100005]; bool cmp(node x,node y)
{
if(x.a!=y.a)
return x.a<y.a;
return x.b<y.b;
} int main()
{
int n;
int T;
scanf("%d",&T);
while(T--)
{scanf("%d",&n);
memset(p,0,sizeof p);
for(int i=0;i<n;i++)
{
scanf("%d%d",&p[i].a,&p[i].b);
}
sort(p,p+n,cmp);
int cnt=0;
while(1)
{
int fl=0;
int ma,mb;
for(int i=0;i<n;i++)
{
if(p[i].flag==0)
{
if(fl==0)
{
ma=p[i].a;
mb=p[i].b;
p[i].flag=1;
fl=1;
}
else
{
if(p[i].a>=ma&&p[i].b>=mb)
{
ma=p[i].a;
mb=p[i].b;
p[i].flag=1;
}
}
}
}
if(fl==0)
break;
cnt++; }
printf("%d\n",cnt);
} return 0;
}

Hdu1051 Wooden Sticks 2017-03-11 23:30 62人阅读 评论(0) 收藏的更多相关文章

  1. 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏

    动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...

  2. HDU2680 Choose the best route 最短路 分类: ACM 2015-03-18 23:30 37人阅读 评论(0) 收藏

    Choose the best route Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. string 与char* char[]之间的转换 2015-04-09 11:30 29人阅读 评论(0) 收藏

    1.首先必须了解,string可以被看成是以字符为元素的一种容器.字符构成序列(字符串).有时候在字符序列中进行遍历,标准的string类提供了STL容器接口.具有一些成员函数比如begin().en ...

  4. IOS即时通讯XMPP搭建openfire服务器 分类: ios技术 2015-03-07 11:30 53人阅读 评论(0) 收藏

    一.下载并安装openfire 1.到http://www.igniterealtime.org/downloads/index.jsp下载最新openfire for mac版 比如:Openfir ...

  5. 【Lucene4.8教程之二】索引 2014-06-16 11:30 3845人阅读 评论(0) 收藏

    一.基础内容 0.官方文档说明 (1)org.apache.lucene.index provides two primary classes: IndexWriter, which creates ...

  6. HDU2033 人见人爱A+B 分类: ACM 2015-06-21 23:05 13人阅读 评论(0) 收藏

    人见人爱A+B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  7. HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏

    Automatic Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  8. 第十二届浙江省大学生程序设计大赛-Lunch Time 分类: 比赛 2015-06-26 14:30 5人阅读 评论(0) 收藏

    Lunch Time Time Limit: 2 Seconds Memory Limit: 65536 KB The 999th Zhejiang Provincial Collegiate Pro ...

  9. pascal矩阵 分类: 数学 2015-07-31 23:01 3人阅读 评论(0) 收藏

    帕斯卡矩阵 1.定义       帕斯卡矩阵:由杨辉三角形表组成的矩阵称为帕斯卡(Pascal)矩阵. 杨辉三角形表是二次项 (x+y)^n 展开后的系数随自然数 n 的增大组成的一个三角形表. 如4 ...

随机推荐

  1. Web验证方式(4)--JWT

    OAuth协议中说到的AccessToken可以是以下两种: 1.任意只起到标识作用的字符串:这种情况下Resource Server处理请求时需要去找Authorization Server获取用户 ...

  2. 汇编_指令_IRET

    IRET(interrupt return)中断返回,中断服务程序的最后一条指令.   汇编指令IRET [指令格式]IRET   [指令功能]IRET(interrupt return)中断返回,中 ...

  3. python HTMLTestRunner.py

    Mac下HTMLTestRunner.py存放路径: -/anaconda/lib/python3.6/site-packages/HTMLTestRunner.py 已经更改,python3可以直接 ...

  4. Ant+jmeter 实现自动化性能测试

    一.前言 性能测试首选的工具是JMeter,在此不多做介绍,但是不得不说JMeter也是一款非常好的接口测试工具.性能测试过程中手工重复的活动非常多,为了给客户提供一个性能测试报告,我用了一周时间进行 ...

  5. Getting Started(入门)

    欢迎阅读专门针对android开发者的培训课程,在这一系列的课程中,描述了如何通过我们的示例代码来完成特定的任务和功能,这些代码可以灵活地应用到你的应用程序中. 课程被分成了几部分, 第一部分,入门, ...

  6. Spring batch学习 详细配置解读(3)

    第一篇讲到普通job 配置 那么spring  batch 给我们提供了丰富的配置,包括定时任务,校验,复合监听器,父类,重启机制等. 下面看一个动态设置读取文件的配置 1.动态文件读取 <?x ...

  7. TCAM CAM 说明 原理 结构 Verilog 硬件实现

    TCAM 三态内容地址查找存储器,CAM内容地址查找存储器.区别在于TCAM多了一级掩码功能,也就是说可以指定某几位是dont care.匹配的时候0,1都行的意思. 广泛应用于数据流处理领域,本文简 ...

  8. 搭建 redis 集群 (redis-cluster)

    一 所需软件:Redis.Ruby语言运行环境.Redis的Ruby驱动redis-xxxx.gem.创建Redis集群的工具redis-trib.rb 二 安装配置redis  redis下载地址 ...

  9. [X264] MinGW编译x264,VC中调用libx264.dll-------------<参考转>

    1. 下载并按照MinGW,最好就缺省按照    http://sourceforge.net/projects/ ... ler/mingw-get-inst/    把C:\MinGW\bin添加 ...

  10. sass的类型判定

    由于sass的作者是rubyer,因此它的类型与JS有点不一样,但一样可以类推. @charset "utf-8";//必须设置了这个才能编译有中文的注释 $gray: #333; ...