HDU 1051 Wooden Sticks (贪心)
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14126 Accepted Submission(s): 5842
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
#include <stdio.h>
#include <algorithm>
using namespace std;
//1051
typedef struct node
{
int x,y,isUsed;
}NODE; int cmp(NODE a, NODE b)
{
//假设x同样。就按y降序排序
if (a.x == b.x)
{
return a.y>b.y;
}
else
{
return a.x>b.x;
}
} int main()
{
int T,N;
NODE c[5001];
while (scanf("%d", &T)!=EOF)
{
while (T--)
{
scanf("%d", &N);
for (int i=0; i<N; i++)
{
scanf("%d %d", &c[i].x, &c[i].y);
c[i].isUsed = 0;
}
sort(c, c+N, cmp); int time = 0;
for (int i=0; i<N; i++)
{
if (c[i].isUsed == 1)
continue;
int x,y;
x = c[i].x; y = c[i].y;
//标记当前为用过了
c[i].isUsed = 1;
for (int j=i+1; j<N; j++)
{
if (c[j].x<=x && c[j].y<=y && c[j].isUsed == 0)
{
x = c[j].x;
y = c[j].y;
c[j].isUsed = 1;
}
}
time++;
}
printf("%d\n", time);
}
} return 0;
}
HDU 1051 Wooden Sticks (贪心)的更多相关文章
- HDU 1051 Wooden Sticks 贪心||DP
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDU - 1051 Wooden Sticks 贪心 动态规划
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1051 Wooden Sticks 贪心题解
本题一看就知道是最长不减序列了,一想就以为是使用dp攻克了. 只是那是个错误的思路. 我就动了半天没动出来.然后看了看别人是能够使用dp的,只是那个比較难证明其正确性,而其速度也不快.故此并非非常好的 ...
- hdu 1051 wooden sticks (贪心+巧妙转化)
#include <iostream>#include<stdio.h>#include<cmath>#include<algorithm>using ...
- hdu 1051:Wooden Sticks(水题,贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDOJ.1051 Wooden Sticks (贪心)
Wooden Sticks 点我挑战题目 题意分析 给出T组数据,每组数据有n对数,分别代表每个木棍的长度l和重量w.第一个木棍加工需要1min的准备准备时间,对于刚刚经加工过的木棍,如果接下来的木棍 ...
- HDU 1051 Wooden Sticks 造木棍【贪心】
题目链接>>> 转载于:https://www.cnblogs.com/Action-/archive/2012/07/03/2574800.html 题目大意: 给n根木棍的长度 ...
- HDU 1051 Wooden Sticks
题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1 ...
随机推荐
- AndroidManifest.xml配置文件详解
AndroidManifest.xml配置文件对于Android应用开发来说是非常重要的基础知识,本文旨在总结该配置文件中重点的用法,以便日后查阅.下面是一个标准的AndroidManifest.xm ...
- linux命令学习01-mkdir
1.环境说明 centos6.7,2.6.32-573.el6.x86_64 2.man mkdir NAM mkdir - make directories SYNOPSI ...
- 12.java.lang.NoSuchMethodException
java.lang.NoSuchMethodException 方法不存在异常 当程序试图通过反射来创建对象,访问(修改或读取)某个方法,但是该方法不存在就会引发异常
- Centos6.8下安装oracle_11gr2版主要过程
安装前准备 下载oracle版本 地址:http://docs.oracle.com/cd/E21901_01/index.html ,下载2个文件分别是 linux.x64_11gR2_databa ...
- zoj 3665 Yukari's Birthday(枚举+二分)
Yukari's Birthday Time Limit: 2 Seconds Memory Limit: 32768 KB Today is Yukari's n-th birthday ...
- Android 开发佳站3
eclipse 某些java文件乱码 摘要: [一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/archive/2013/04/24/3040219.h ...
- git、githup使用
一.git安装.配置 git安装: root@ubuntu~# apt-get install git git配置githup/自己的git服务器端账号, 即在用户的home目录下生成.gitco ...
- 一步一步学c#(四):继承
继承 1·继承的类型 在面向对象的编程中,有两种截然不同的继承类型,实现继承和接口继承. 实现继承:表示一个类型派生于一个基类型,它拥有该基类型的所有成员字段和函数. 接口继承:表示一个类型只继承了函 ...
- Ueditor和CKeditor 两款编辑器的使用与配置
一丶ueditor 百度编辑器 1.官方文档,演示,下载地址:http://ueditor.baidu.com/website/index.html 2.百度编辑器的好:Editor是由百度web前端 ...
- java中关于如何运行jar格式程序的说明
通常情况下,我们用打包工具如Eclipse的export工具制作的jar包是无法通过鼠标双击来运行的. 此时我们需要启动DOS窗体,在DOS窗体中输入java命令运行程序(前提是你的环境变量class ...