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 ...
随机推荐
- Windows2008RT搭建VPN服务器
总结一下2008系统搭建VPN的步骤和过程,自己有个人网站和服务要通过互联网发布出来.服务器放在自己家里,宽带是民用的.也就产生了服务发布的一些问题.用无法映射出真实的公网IP,或是一些其他内部的问题 ...
- 【转】 UIButton上使用UIEdgeInsetsMaketitle跟图片对齐
[转]http://blog.csdn.net/yanxiaoqing/article/details/7230660 默认情况下,不设置的效果,都使居中现实,button为150*150 使用以下设 ...
- 使用MySQL处理百万级以上数据时,不得不知道的几个常识
最近一段时间参与的项目要操作百万级数据量的数据,普通SQL查询效率呈直线下降,而且如果where中的查询条件较多时,其查询速度简直无法容忍.之前数据量小的时候,查询语句的好坏不会对执行时间有什么明显的 ...
- [LeetCode][Python]ZigZag Conversion
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/zigzag- ...
- [LeetCode][Python]Median of Two Sorted Arrays
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/median-of-two-sorted-arrays/ There are two ...
- Pro Android学习笔记(十一):了解Intent(中)
Intent的构成 Intent能够带有action,data(由URI表达),extra data(key/value map,键值对),指定的类名(成为component name).一个inte ...
- 获取第下一个兄弟元素 屏蔽浏览器的差异(nextElementsibling)
//获取element下一个兄弟元素 function getNextElementSibling(element){ //能力检测 判断是否支持nextElementSibling if(eleme ...
- English - 英文写作中的最常见“十大句式”
英文写作中的最常见“十大句式” from 小木虫论坛 一.否定句 许多否定句不含not的否定结构.如果论文作者能正确使用他们,就会增加写作的闪光点,使文章显得生动活泼. 1.Instead of in ...
- C# XML与Json之间相互转换
XML转换为Json字符串 在代码中预定义的一个xml字符串,如下: string xml = @"<?xml version=""1.0"" ...
- C - 字符识别?
C - 字符识别? Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%lld & %llu Submit Sta ...