HDU 1051:Wooden Sticks
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11605 Accepted Submission(s): 4792
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<= n <=5000)组二维坐标点,凡是满足 "x1<= x2 && y1<= y2"的话那么我们承认这两个坐标是属于同一个集合中。题目要我们求出这些坐标点最少能表示成几个集合。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue> using namespace std; const int maxn = 5000 + 50; int cas;//案例
int n;//木条数量
int vis[maxn];//标记数组
int ans_minute;//最短时间 struct point
{
int l;//长度
int w;//重量
};
point s[maxn]; bool cmp(point a, point b)
{
if( a.l==b.l )return a.w<b.w;
else return a.l<b.l;
} int main()
{
scanf("%d", &cas);
while( cas-- )
{
scanf("%d", &n);
ans_minute = 0;
memset(vis, 0, sizeof(vis));
for(int i=1; i<=n; i++)scanf("%d%d", &s[i].l, &s[i].w);
sort(s+1, s+n+1, cmp);
//for(int i=1; i<=n; i++)printf("%d__%d ", s[i].l, s[i].w);
int judge = 1;
for(int i=1; i<=n; i++)
{
if( vis[i] ) continue;
ans_minute++;
int temp = s[i].w;
vis[i] = 1;
for(int j=i+1; j<=n; j++)
{
if( temp<=s[j].w && !vis[j] )
{
temp = s[j].w;
judge++;
vis[j] = 1;
continue;
}
}
if(judge>=n)break;
} printf("%d\n", ans_minute);
}
}
HDU 1051:Wooden Sticks的更多相关文章
- HDU 1051: Wooden Sticks(贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU1051:Wooden Sticks
Problem Description There is a pile of n wooden sticks. The length and weight of each stick are know ...
- HDU 1051 Wooden Sticks (贪心)
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- 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 ...
- HDU ACM 1051/ POJ 1065 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 ...
- HDU 1005 Wooden Sticks
http://acm.hdu.edu.cn/showproblem.php?pid=1051 Problem Description There is a pile of n wooden stick ...
随机推荐
- vim高级编辑(一)
本文出自 http://blog.csdn.net/shuangde800 ------------------------------------------------------------ ...
- Spring的datasource配置详解
一句话,Spring对Hibernate的整合,是在applicationContext.xml中配置sessionFactory来实现的,其中sessionFactory中要装配dataSource ...
- oracle乱码问题
oracle乱码问题通常是因为oracle字符集设置和操作系统字符集设置不一致造成的,这里不得不提到两个操作系统环境变量,LANG和NLS_LANG LANG是针对Linux系统的语言.地区.字符集的 ...
- 单例模式 - 程序实现(Java)
我们知道单例模式,其实就是返回一个被调用类的实例. 在频繁的进行实例(Instance)创建过程,难免过多的进行new InstanceName():我们可以只通过调用一个方法解决. 在进行设计模式的 ...
- javamail发送邮件的简单实例(转)
javamail发送邮件的简单实例 今天学习了一下JavaMail,javamail发送邮件确实是一个比较麻烦的问题.为了以后使用方便,自己写了段代码,打成jar包,以方便以后使用.呵呵 以下三段代码 ...
- 用JS实现发邮件的功能 完美解决
怎样用JS实现发邮件的功能? 我想用JS实现把页面文本框中的内容直接通过邮件的方式发送到一个指定的邮箱.fengxq给出的答案是<script language=javascript>if ...
- solr4.9r+ Eclipse 4.3+ tomcat 7.5 +winds7(二)
尊重原创,原文地址:http://blog.csdn.net/chunlei_zhang/article/details/38778945 这另外一种方法是将solr项目部署到tomcat上,执行to ...
- 在ASP.NET MVC 中获取当前URL、controller、action(转)
URL的获取很简单,ASP.NET通用: [1]获取 完整url (协议名+域名+虚拟目录名+文件名+参数) string url=Request.Url.ToString(); [2]获取 虚拟目录 ...
- c++对象指针-01(转载)
1.指向对像的指针在建立对像时,编译系统会为每一个对像分配一定的存储空间,以存放其成员,对像空间的起始地址就是对像的指针.可以定义一个指针变量,用来存和对像的指针.如果有一个类:class Time{ ...
- session深入解读
林炳文Evankaka原创作品.转载请注明出处http://blog.csdn.net/evankaka 摘要:尽管session机制在web应用程序中被採用已经非常长时间了.可是仍然有非常多人不清楚 ...