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 ...
随机推荐
- UVA 10313(完全背包变形)
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...
- MVVM Light须要注意的10个问题
MVVM Light须要注意的10个问题 从使用XAML技术基础開始(实际上并非非常久曾经).我便关注MVVM(Model – View – ViewModel)模式.偶然接触到MVVM Light不 ...
- jQuery 弹出窗口的形式一直是具体案件的中心
在网上查 多 不是不符合无效;因此,一些自己总结,解决这个问题 原则: 常见问题: 弹出层居中了,背景也是半透明的 可是发现一拉动滚动栏立即就露馅了发现背景仅仅设置了屏幕所在段,其它部分都是原来 ...
- Devstack: A copy of worked local.conf I'm sharing with you.
service_plugins = neutron.services.firewall.fwaas_plugin.FirewallPlugin [service_providers] service_ ...
- 什么样的企业造什么样的软件最easy成功?
事件1: 一般软件企业按功能分,大体分业务应用型软件和系统工具型软件. 按市场分,应用型软件企业较多,直接贴近生活:系统工具类较少,间接贴近大众较少. 事件2: 软件企业中,当中中小型企业老板存在非常 ...
- FMOD在Android玩音响系统的抖动问题
1. 基本介绍 在Android升级系统Android4.4之后,发现FMOD在Android音会出现抖动.导致声音不正常.边赫赫有名的"极品飞车"都有问题. 经查验,是FMOD的 ...
- 通过Java反射调用方法
这是个测试用的例子,通过反射调用对象的方法. TestRef.java import java.lang.reflect.Method; import java.lang.reflect.In ...
- 一个linux常见命令的列表
这是一个linux常见命令的列表. 那些有• 标记的条目,你可以直接拷贝到终端上而不需要任何修改,因此你最好开一个终端边读边剪切&拷贝. 所有的命令已在Fedora和Ubuntu下做了测试 命 ...
- How to debug with IntelliJ IDEA + Grails 2.3.x (转)
问题: 最近访问grails.org,看到grails framework已经发展到2.3.x了,不免想尝尝鲜.下载了最新的grails-2.3.x之后,创建了一个新的grails app. 添加Bo ...
- cocos2dx 3.1从零学习(六)——CocosStudio(VS2013project导入及环境设置)
导入libCocosStudio.libExtensions.libGUI 新建的project例如以下图: 加入现有项目 右键解决方式.例如以下操作: watermark/2/text/aHR0cD ...