HDU-1051 Wooden Sticks
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3902 Accepted Submission(s): 1621
(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).
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
1
3
题义:给定若干(1<= n <=5000)组二维坐标点,凡是满足 "x1<= x2 && y1<= y2"的话那么我们承认这两个坐标是属于同一个集合中。题目要我们求出这些坐标点最少能表示成几个集合。
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).
先将所有的点的信息保存起来,然后选取 x 或者 y 作为对象进行排序,排序中注意如果两个点的 x相同,那么这时候要保持 y有序。这样做的目的是使得所有集合线性的呈现出来,可以理解为经过这样一次排序后,能够每次从前到后找到一个包含点满足题义且最多的点集。不会出现正确分离出来的集合在该排列中有元素是逆序的。
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>int T;struct E
{int len, wi;
} e[5010];char hash[5010];int cmp( const void *a, const void *b )
{if( ( ( struct E * )a )-> len!= ( ( struct E * )b )-> len ){return ( ( struct E * )a )-> len- ( ( struct E * )b )-> len;}else{return ( ( struct E * )a )-> wi- ( ( struct E * )b )-> wi;}
}int find( int N )
{for( int i= 0; i< N; ++i ){if( !hash[i] ){return i;}}return -1;
}bool ok( int i, int baselen, int basewi )
{if( e[i].wi>= basewi ){return true;}else{return false;}
}int main( )
{scanf( "%d", &T );while( T-- ){memset( hash, 0, sizeof( hash ) );int N, time= 0;scanf( "%d", &N );for( int i= 0; i< N; ++i ){scanf( "%d %d", &e[i].len, &e[i].wi );}qsort( e, N, sizeof( e[0] ), cmp );int sta;while( 1 ){sta= find( N );// printf( "sta=%d\n", sta );if( sta== -1 ){break;}int baselen= e[sta].len, basewi= e[sta].wi;// printf( "blen= %d, bwi= %d\n", baselen, basewi );for( int i= sta; i< N; ++i ){//printf( "blen= %d, bwi= %d\n", baselen, basewi );if( !hash[i]&& ok(i, baselen, basewi ) ){hash[i]= 1;//printf( "..%d ..%d\n", e[i].len, e[i].wi );baselen= e[i].len;basewi= e[i].wi;}}++time;}printf( "%d\n", time );}
}/*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*/
转载于:https://www.cnblogs.com/Lyush/archive/2011/07/10/2102198.html
HDU-1051 Wooden Sticks相关推荐
- HDU - 1051 Wooden Sticks
有一堆n个木棍.每个棒的长度和重量是预先知道的.木棒要用木工机械逐一加工.它需要一些时间,称为设置时间,机器准备加工一根棍子.安装时间与清洗操作和更换机器中的工具和形状有关.木工机床的安装时间如下: ...
- HDU 1051 Wooden Sticks 造木棍【贪心】
题目链接>>> 转载于:https://www.cnblogs.com/Action-/archive/2012/07/03/2574800.html 题目大意: 给n根木棍的长度 ...
- Wooden Sticks POJ - 1065(最大上升子序列+动态规划状态转移思维)
题意: 给你n个木棍的长度和重量,让其成为上升序列,如果不能达到,就需要重新一分钟设置. a)第一个木棍的准备时间为1分钟. b)在处理长度为l和重量为w的棒之后,如果l <= l'并且w &l ...
- 1270: Wooden Sticks [贪心]
点击打开链接 1270: Wooden Sticks [贪心] 时间限制: 1 Sec 内存限制: 128 MB 提交: 31 解决: 11 统计 题目描述 Lialosiu要制作木棍,给n根作为原料 ...
- hdu1051 Wooden Sticks
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1051 大意:求最少升序序列的个数. #include <cstdio> #include &l ...
- 【HDU - 1455】Sticks (dfs + 剪枝)
题干: George took sticks of the same length and cut them randomly until all parts became at most 50 un ...
- HDU Problem - 1455 Sticks
题目链接 Problem Description George took sticks of the same length and cut them randomly until all parts ...
- ZOJ 1025 Wooden Sticks(快排+贪心)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=25 题目大意:机器运送n个木条,每个木条有一个长度和重量.运送第一根木 ...
- poj 1065 Wooden Sticks
/* 先按l排序 再每次找出一段最长的递增序列! */ #include <stdio.h> #include <stdlib.h> #include <string.h ...
最新文章
- 参悟JavaScript
- 活动目录(Active Directory)安装
- 带参数的方法;导入包
- 【原创】大叔问题定位分享(33)oozie提交任务报错ArithmeticException: / by zero
- php将配置信息写入文件,Php写入配置文件的经典漏洞
- openssl1.1.0 支持php,openssl升级到1.0.21以支持nginx http2 ssl
- Android检查网络状态步骤
- 【数学基础】一份非常适合人工智能学习的概率论基础材料中文版 (CS229概率论)...
- 使用FuncT, TResult 委托实现API日志的记录
- Sqlite优化记录:使用全文索引加快检索速度-转
- android系统源代码单独编译应用程序
- 实时 摔倒识别 /运动分析/打架等异常行为识别/控制手势识别等所有行为识别全家桶 原理 + 代码 + 数据+ 模型 开源!
- 名编辑电子杂志大师教程 | PDF制作排版设计建议
- 应用时间序列分析案例操作--基于SAS软件,以北京市1980-2009年降水量为对象
- java 自定义列表_自定义列表标签
- Oracle ORA12514 监听程序当前无法识别连接描述符中请求的服务问题解决
- 浅谈电力系统短路故障的分析
- Xcode No certificate for team ‘xxx‘ matching ‘iPhone Developer: xxx (xxx)‘
- iOS绘图详解-多种绘图方式、裁剪、滤镜、移动、CTM
- Python通过蒙特卡罗法计算π值
热门文章
- LeetCode Wiggle Subsequence(动态规划)
- python读取有中文文件时的报错处理
- LeetCode Count Numbers with Unique Digits(计数问题)
- scrapy-redis组件写分布式爬虫实战
- E.Text Editor (Gym 101466E + 二分 + kmp)
- Django——restframework(serializers序列化工具)
- iBatis报java.lang.RuntimeException: Error setting property错误
- 「3」Java开发环境搭建
- [LintCode] Single Number 单独的数字
- gnujaxp.jar与struts2中的xwork核心包冲突