POJ 1065 Wooden Sticks【贪心】
题意:
有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列。问至少要分为多少个序列。且要保证排出来的子序列数最少。
思路:
( 9 , 4 ) ,( 2 , 5 ) ,( 1 , 2 ) ,( 5 , 3 ),( 4 , 1 )可以排成这样
( 4 , 1 ) , ( 5 , 3 ) , ( 9 , 4 ); ( 1 , 2 ) , ( 2 , 5 ) .
其中:(4,1)<=(5,3)<=(9,4)为不降序列,(4,1)<(5,3)由于4<5&&1<3
(1,2)<(2,5)为不降序列。即最少的不降子序列为2,输出2
#include<iostream>
#include<algorithm>
using namespace std;
const int MAX = 5001;
struct wooden{
int l, w, flag;
}wd[MAX];
bool cmp(wooden x, wooden y){
if (x.l != y.l) return x.l < y.l;
return x.w < y.w;
}
int main()
{
int T;
cin >> T;
while (T--)
{
int n;
cin >> n;
for (int i = 0; i < n; i++){
cin >> wd[i].l >> wd[i].w;
wd[i].flag = 0;
}
sort(wd, wd + n, cmp);
int res = 0;
for (int i = 0; i < n; i++){
if (wd[i].flag)continue;
res++;
int cur = wd[i].w;
for (int j = i + 1; j < n; j++){
if (!wd[j].flag && wd[j].w >= cur){
wd[j].flag = 1;
cur = wd[j].w;
}
}
}
cout << res << endl;
}
return 0;
}
POJ 1065 Wooden Sticks【贪心】的更多相关文章
- POJ 1065 Wooden Sticks#贪心+qsort用法
(- ̄▽ ̄)-* 这道题用到了cstdlib库的qsort()函数: 用法链接:http://www.cnblogs.com/syxchina/archive/2010/07/29/2197382.h ...
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- POJ 1065 Wooden Sticks (贪心)
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...
- HDU ACM 1051/ POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- poj -1065 Wooden Sticks (贪心or dp)
http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...
- poj 1065 Wooden Sticks 【贪心 新思维】
题目地址:http://poj.org/problem?id=1065 Sample Input 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 ...
- POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)
题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...
- POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列
POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...
随机推荐
- hive vs hbase
HIVE和HBASE区别 两者分别是什么? Apache Hive是一个构建在Hadoop基础设施之上的数据仓库.通过Hive可以使用HQL语言查询存放在HDFS上的数据.HQL是一种类SQL语言,这 ...
- 获取客户端的请求IP地址
获取客户端的请求IP地址 package com.microClass.util; import javax.servlet.http.HttpServletRequest; import java. ...
- 02-里氏替换原则(LSP)
1. 背景 有一个功能p1,由类A完成,现在需要将功能p1进行扩展,扩展后的功能为p3,p3由原功能p1和新功能p2组成,而新功能p3和p2均由类A的子类B来完成,子类B在完成新功能p2的同时,可能会 ...
- vue自学入门-1(Windows下搭建vue环境)
本人是一个喜欢动手的程序员,先跑起来个HelloWorld,增加感性认识,这三篇入门文章,花了不到一个小时,从网上找资料,程序跑通后,整理出来的,有的新人可能去哪找资料,运行代码都不知道,分享出来,大 ...
- Windows句柄数限制
设置 GDIProcessHandleQuota项设置GDI句柄数量,默认值为2710(16进制)/10000(10进制),该值的允许范围为 256 ~ 16384 ,将其调整为大于默认的10000的 ...
- ADB not responding
1.如下错误: 2.执行 如下代码 : netstat -aon|findstr "5037" 3.打开任务管理器 找到PID 为 5536 的进程 将该进程关闭 4.重启 A ...
- HDU 2522 A simple problem (模拟)
题目链接 Problem Description Zty很痴迷数学问题..一天,yifenfei出了个数学题想难倒他,让他回答1 / n.但Zty却回答不了^_^. 请大家编程帮助他. Input 第 ...
- Managers经理/代理形式的数据共享
代理方式实现进程间共享字典和列表形式的数据, 代码块: import os from multiprocessing import Process,Manager def f(d,l,normalLi ...
- Node、PHP、Java 和 Go 服务端 I/O 性能PK
http://blog.csdn.net/listen2you/article/details/72935679
- SpringBoot集成监控管理
(1).添加starter依赖 <dependency> <groupId>org.springframework.boot</groupId> <artif ...