1051 Wooden Sticks
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 12443 Accepted Submission(s): 5167
(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).
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct ln{
int x;
int y;
int z;
}a[];
bool cmp(const ln a,const ln b)
{
if(a.y==b.y)
return a.x<b.x;
else
return a.y<b.y;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
memset(a,,sizeof(a));
int n;
scanf("%d",&n);
for(int i=;i<n;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].z=;
}
sort(a,a+n,cmp);
int count=,length;
for(int i=;i<n;i++)
{
if(!a[i].z)
{
count++;
length=a[i].x;
for(int j=i+;j<n;j++)
{
if(!a[j].z)
{
if(a[j].x>=length)
{
a[j].z=;
length=a[j].x;
}
} }
} }
printf("%d\n",count);
}
return ;
}
1051 Wooden Sticks的更多相关文章
- HDOJ 1051. Wooden Sticks 贪心 结构体排序
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 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 贪心||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(水题,贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 杭电 1051 Wooden Sticks
Description There is a pile of n wooden sticks. The length and weight of each stick are known in adv ...
- HDOJ 1051. Wooden Sticks
题目 There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The ...
- HDU 1051 Wooden Sticks
题意: 有 n 根木棒,长度和质量都已经知道,需要一个机器一根一根地处理这些木棒. 该机器在加工过程中需要一定的准备时间,是用于清洗机器,调整工具和模板的. 机器需要的准备时间如下: 1.第一根需要1 ...
随机推荐
- c语言结构体指针初始化
今天来讨论一下C中的内存管理. 记得上周在饭桌上和同事讨论C语言的崛起时,讲到了内存管理方面 我说所有指针使用前都必须初始化,结构体中的成员指针也是一样 有人反驳说,不是吧,以前做二叉树算法时,他的左 ...
- Android 技术用于汇总
id 名词 含义 详细 1 Android CTS CTS 全称 Compatibility Test Suite 兼容性测试工具 当产品开发出来以后,并定制了自己的 Android 系统后 ...
- sql server 查询多个不关联表且对结果编号
1.除非另外还指定了 TOP 或 FOR XML,否则,ORDER BY 子句在视图.内联函数.派生表.子查询和公用表表达式中无效. 解决方法:top 100 percent * 2.如何对查询结果编 ...
- crontab的应用
当我们需要定时执行某个系统内的php脚本程序时,可以这样设置crontab * 19 * * * /usr/local/php/bin/php /var/www/test.php 此处表示调用php( ...
- HTML5的页面资源预加载技术(Link prefetch)加速页面加载
不管是浏览器的开发者还是普通web应用的开发者,他们都在做一个共同的努力:让Web浏览有更快的速度感觉.有很多已知的技术都可以让你的网站速度变得更快:使用CSS sprites,使用图片优化工具,使用 ...
- pyinstall 使用笔记
1.下载pyinstaller 目前pyinstaller支持的python版本为2.3-2.7,可以到http://www.pyinstaller.org/官网下载. 2.安装 下载完成后,解压即可 ...
- sublimetext2 中运行Python提示EOFError: EOF when reading a line
解决方法:一.安装sublimeREPL 打开sublimeText2按CTRL+SHIFT+P,英文版输入:install后选择Package Control: Install Package ...
- 开源免费的C/C++网络库(c/c++ sockets library)
(1)ACE 庞大.复杂,适合大型项目.开源.免费,不依赖第三方库,支持跨平台. http://www.cs.wustl.edu/~schmidt/ACE.html (2)Asio Asio基于Boo ...
- 6、WPF中的特殊字符与空白
特殊字符: 小于号 < 字符实体采用<表示 大于号 > 字符实体采用>表示 &符号 字符实体采用&表示 引号"&quo ...
- hadoop相关问题
发现一篇不错的文章,转一下.http://www.cnblogs.com/xuekyo/p/3386610.html HDFS导论(转) 1.流式数据访问 HDFS的构建思想是这样的:一次写入,多 ...