Hdu1051 Wooden Sticks 2017-03-11 23:30 62人阅读 评论(0) 收藏
Wooden Sticks
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).
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.
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
2
1
3
————————————————————————————————————
题目的意思是给出若干个物品的长度和质量,调整机器需要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) 收藏的更多相关文章
- 动态链接库(DLL) 分类: c/c++ 2015-01-04 23:30 423人阅读 评论(0) 收藏
动态链接库:我们经常把常用的代码制作成一个可执行模块供其他可执行文件调用,这样的模块称为链接库,分为动态链接库和静态链接库. 对于静态链接库,LIB包含具体实现代码且会被包含进EXE中,导致文件过大, ...
- 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 ...
- string 与char* char[]之间的转换 2015-04-09 11:30 29人阅读 评论(0) 收藏
1.首先必须了解,string可以被看成是以字符为元素的一种容器.字符构成序列(字符串).有时候在字符序列中进行遍历,标准的string类提供了STL容器接口.具有一些成员函数比如begin().en ...
- IOS即时通讯XMPP搭建openfire服务器 分类: ios技术 2015-03-07 11:30 53人阅读 评论(0) 收藏
一.下载并安装openfire 1.到http://www.igniterealtime.org/downloads/index.jsp下载最新openfire for mac版 比如:Openfir ...
- 【Lucene4.8教程之二】索引 2014-06-16 11:30 3845人阅读 评论(0) 收藏
一.基础内容 0.官方文档说明 (1)org.apache.lucene.index provides two primary classes: IndexWriter, which creates ...
- 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 ...
- 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 ...
- 第十二届浙江省大学生程序设计大赛-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 ...
- pascal矩阵 分类: 数学 2015-07-31 23:01 3人阅读 评论(0) 收藏
帕斯卡矩阵 1.定义 帕斯卡矩阵:由杨辉三角形表组成的矩阵称为帕斯卡(Pascal)矩阵. 杨辉三角形表是二次项 (x+y)^n 展开后的系数随自然数 n 的增大组成的一个三角形表. 如4 ...
随机推荐
- 【monkeyrunner】monkeyrunner脚本录制和回放
脚本录制 1.连接你已经打开调试模式的ANDROID设备或模拟器,输入adb devices 2.运行录制脚本.在cmd窗口输入 monkeyrunner recorder.py #recorder. ...
- 【升级至sql 2012】sqlserver mdf向上兼容附加数据库(无法打开数据库 'xxxxx' 版本 611。请将该数据库升级为最新版本。)
sqlserver mdf向上兼容附加数据库(无法打开数据库 'xxxxx' 版本 611.请将该数据库升级为最新版本.) 最近工作中有一个sqlserver2005版本的mdf文件,还没有log文件 ...
- Python中表达式和语句及for、while循环练习
Python中表达式和语句及for.while循环练习 1)表达式 常用的表达式操作符: x + y, x - y x * y, x / y, x // y, x % y 逻辑运算: x or y, ...
- [java]经验集
Calendar c = Calendar.getInstance(); c.set(1999,12,21); SimpleDateFormat sdf = new SimpleDateFormat( ...
- echarts地图扩展文件使用geoJson格式。
echarts地图扩展文件使用geoJson格式. 1.在线生成 http://ecomfe.github.io/echarts-map-tool/ 这里可以生成省市区的json,但是最多生成到”区 ...
- VS2017如何配置openGL环境
转自:http://blog.csdn.net/qq_26982531/article/details/62056913 这里着重介绍vs2017配置openGL环境与以前版本的不同之处: ...
- servlet中获取配置文件中的参数.
web.xml (添加init-param) <?xml version="1.0" encoding="UTF-8"?> <web-app ...
- 「小程序JAVA实战」小程序视频播放的时候生命周期的控制(56)
转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxushipinbofangdeshihoushengmingzhouqi ...
- FireDAC 汉字字段名称过滤
[FireDAC][Stan][Eval]-107. Invalid character found [ 拼音码 like '%A%' ] 英文字段名称过滤正常 汉字字段名过滤报错. 莫非不支持汉字字 ...
- Python 2.75升级3.6.3
https://blog.csdn.net/wwwdaan5com/article/details/78218277 Centos 7 默认yum安装python 是2.7.5, (网上看了很多升级都 ...