HDU1051Wooden Sticks
来源:互联网 发布:org域名申请 编辑:程序博客网 时间:2024/05/29 06:50
Wooden Sticks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 21183 Accepted Submission(s): 8546
(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).
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
213
题意:给你n个棍子,和他们的重量W高度h求最小准备时间。第一根木棍的准备时间为1分钟。往后如果W<=W',H<=H'的准备时间为0分钟,反之为1分钟。
思路:先按照W对他们进行排序,以后按照H从上往下找比他大的
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
struct node
{
int x,y;
}a[5001];
int vis[5001];
int cmp(node b,node c )
{
return b.x<=c.x;
}
int main()
{
int t;
cin>>t;
for(int i=1;i<=t;i++)
{
int n;
cin>>n;
for(int j=0;j<n;j++)
{
cin>>a[j].x>>a[j].y;
}
sort(a,a+n,cmp);
int s=0;
memset(vis,0,sizeof(vis));
for(int j=0;j<n;j++)
{
int p=j;
if(!vis[j])
{
vis[j]=1;
for(int k=j+1;k<n; k++)
{
if(!vis[k]&&a[p].y<=a[k].y)
{
vis[k]=1;
p=k;
continue;
}
}
s++;
}
}
cout<<s<<endl;
}
return 0;
}
- HDU1051Wooden Sticks
- hdu1051Wooden Sticks
- HDU1051Wooden Sticks
- HDU1051Wooden Sticks(贪心)
- hdu1051Wooden Sticks(贪心)
- hdu1051Wooden Sticks(贪心)
- Sticks
- sticks
- sticks
- sticks
- Sticks
- sticks
- Sticks
- Sticks
- Sticks
- Sticks
- Sticks
- Sticks
- SQL SERVER中求上月、本月和下月的第一天和最后一天
- Android数据存储和访问之SQLite存储
- static和final的位置问题
- vim 作为python2.7 IDE的配置
- JAVA设计模式十七--Composite(组合模式)
- HDU1051Wooden Sticks
- 最大子段和
- Linux IO模式及 select、poll、epoll详解
- 滚动条插件使用 --笔记
- 程序的安装方法
- 秒杀系统架构分析与实战
- 代理模式(Proxy Pattern、Surrogate Pattern 对象结构型模式)
- 健康不胖
- 启动Mininet时报ovsdb-server没有启动的错误