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 ...
随机推荐
- SQL Developer更改日期显示格式
工具->首选项->数据库->NLS->日期格式: DD-MON-RR 修改为: YYYY-MM-DD HH24:MI:SS
- try catch finally ,try 中有return时怎么执行
- 黄聪:WordPress 多站点建站教程(二):后台(管理网络)设置详解,如何管理子站的用户、主题、插件、设置等功能
建立好了子站,我们需要有个地方配置所有子站的主题.插件等功能,我们可以在后台看到 我的站点--管理网络 如下图: 在 管理网络--仪表盘 里面,我们可以创新用户和站点,也提供了查询功能. 要注意的是: ...
- [转][javascript]判断传入参数
// IE 下 name 都是 undefined ,这里手动赋值 Number.name="Number"; //String.name="String"; ...
- 在 Ubuntu 16.04 LTS 上 离线安装 Docker / Docker-compose
前情提要 今天上班后,突然接到现场的工程师的电话: XXX的现场环境组的的局域网,上不了互联网.bla bla bla..... 如果需要安装其他软件的话,只能是自己带过去安装... 听完现场工程师的 ...
- Keras函数式 API
用Keras定义网络模型有两种方式, Sequential 顺序模型 Keras 函数式 API模型 之前我们介绍了Sequential顺序模型,今天我们来接触一下 Keras 的函数式API模型. ...
- mysql修复表
数据库Table xxx is marked as crashed and should be repaired错误的解决方法服务器断电等原因可能导致数据表损坏,导致访问的时候提示:Table xxx ...
- pm无力的话
1. 先这样做吧, 等不行再改 2. 用户的需求不明确, 他们对于自己的业务也不明白, 现在是我们在帮助他们缕清自己的业务, 这个迭代的过程中,有很多问题,我们程序员既不能参与到业务, 也不能猜测业务 ...
- C# Panel控件截图
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll ")] private static extern bo ...
- 在线OFFICE方案
Office在线预览及PDF在线预览的实现方式大集合 在线浏览office 文件 在线预览文档openoffice+swfTool 类百度文库文档上传.转换和展示功能项目开源代码 微软的office ...