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= ...
随机推荐
- UVALive 4850 Installations 贪心
题目链接 题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...
- Linux_安装
总结: 分区-->格式化-->起一个设备文件名(逻辑分区一定从5开始)-->指定挂载点(必须是空的目录名称作为盘幅)
- openvpn路由配置
openvpn路由配置 通常openvpn部署好以后,客户端连接VPN后会被配置一些路由,其客户端的路由会被修改为所有的流量都通过VPN来传输.但有时候,我们需要客户端的某些IP走VPN或者本地网关. ...
- u-boot移植(一)---准备工作
一.工具链的制作 1.1 工具 软件工具:crosstool-ng 下载地址:git clone https://github.com/crosstool-ng/crosstool-ng crosst ...
- Asp.net MVC Session过期异常的处理
一.使用MVC中的Filter来对Session进行验证 (1)方法1: public class MyAuthorizeAttribute : FilterAttribute, IAuthoriza ...
- JavaScript之Dom1|DOM2|DOM3之DOM1【节点层次】
长文慎读. 导航: 1.节点层次 2.Node类型 3.Document类型 4.Element类型 5.Text类型 6.Comment类型 7.CDATASection类型 8.DocumentT ...
- Ubuntu 18.04换国内源 中科大源 阿里源 163源 清华源
感觉还是18.4好用,所以最近装回了18,感觉现在18的兼容性也还可以了,深度学习的环境配置都没有问题,就是安装软件的时候有点慢,所以想要更新一下源. 第一步: 编辑/etc/apt/sources. ...
- POJ 2503 Babelfish (STL)
题目链接 Description You have just moved from Waterloo to a big city. The people here speak an incompreh ...
- [CQOI2018]交错序列 (矩阵快速幂,数论)
[CQOI2018]交错序列 \(solution:\) 这一题出得真的很好,将原本一道矩阵快速幂硬生生加入组合数的标签,还那么没有违和感,那么让人看不出来.所以做这道题必须先知道(矩阵快速幂及如何构 ...
- block循环引用
block里边会有循环引用的风险,它可能对外部一个变量出现强引用,所以需要判断里边是否有循环引用,通过dealloc方法(销毁当前控制器.或销毁要测试的变量),判断是否循环引用.主要在block 里边 ...