POJ 1065 Wooden Sticks Greed,DP
排序后贪心或根据第二关键字找最长下降子序列
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<sstream>
#include<cmath>
#include<climits>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define pb(a) push(a)
#define INF 0x1f1f1f1f
#define lson idx<<1,l,mid
#define rson idx<<1|1,mid+1,r
#define PI 3.1415926535898
template<class T> T min(const T& a,const T& b,const T& c) {
return min(min(a,b),min(a,c));
}
template<class T> T max(const T& a,const T& b,const T& c) {
return max(max(a,b),max(a,c));
}
void debug() {
#ifdef ONLINE_JUDGE
#else freopen("in.txt","r",stdin);
freopen("d:\\out1.txt","w",stdout);
#endif
}
int getch() {
int ch;
while((ch=getchar())!=EOF) {
if(ch!=' '&&ch!='\n')return ch;
}
return EOF;
} const int maxn=;
struct node
{
int l,w;
bool operator < (const node &ant) const
{
return l<ant.l||l==ant.l&&w<ant.w;
}
};
node da[maxn];
int vis[maxn];
int main()
{
int t;
scanf("%d", &t);
for(int ca = ; ca <= t; ca++)
{
int n;
scanf("%d", &n);
for(int i = ; i < n; i++)
scanf("%d%d", &da[i].l, &da[i].w);
sort(da, da + n);
memset(vis,,sizeof(vis));
int res=;
for(int cnt=;;)
{
res++;
int curl=-,curw=-;
for(int i=;i<n;i++)
{
if(!vis[i]&&da[i].l>=curl&&da[i].w>=curw)
{
vis[i] = ; cnt++;
curl=da[i].l;curw=da[i].w;
}
}
if(cnt==n)break;
}
printf("%d\n",res);
}
return ;
}
POJ 1065 Wooden Sticks Greed,DP的更多相关文章
- POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心
参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- 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 (贪心)
There is a pile of n wooden sticks. The length and weight of each stick are known in advance. The st ...
- poj -1065 Wooden Sticks (贪心or dp)
http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...
- 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= ...
- 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【贪心】
题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...
随机推荐
- (C#) Tasks 中的异常处理(Exception Handling.)
多线程编程中要注意对线程异常的处理.首先写个例子. 一个线程用于显示信息(Show Messages).主线程用于做其他工作(Do Works). using (Task taskShowMessag ...
- 用wamp配置的环境,想用CMD连接mysql怎么连
签:用wamp配置的环境 想用cmd连接mysql怎么连 进到d盘该目录 (cd切不了盘,就输入盘符加冒号回车,再cd到目录) WAMP装好后,mysql数据库运行时没有 mysql 和 ...
- maven3 手动安装本地jar到仓库
安装命令: mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojd ...
- js实现各种常用排序算法
1.冒泡排序 var bubbleSort = function (arr) { var flag = true; var len = arr.length; for (var i = 0; i &l ...
- LeetCode 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Giv ...
- Mono addin 学习笔记 5 TypeExtensionPoint
1. Attribute声明方式 定义扩展点: [TypeExtensionPoint]public interface ICommand{ void Run();} 定义扩展: [Ex ...
- LVM原理及实现过程
这里引用鸟哥说明 LVM 的重点在於『可以弹性的调整 filesystem 的容量!』而并非在於效能与数据保全上面. 需要文件的读写效能或者是数据的可靠性,请参考前面的 RAID 小节. LVM 可以 ...
- QTdebug时没有调试引擎
问题描述: 在调试程序时,点击调试按钮,弹出no engine. 问题解决: 到官网下载调试的SDK.https://developer.microsoft.com/zh-cn/windows/dow ...
- 高亮代码显示之HTML困惑
近期做样式库,需要将HTML代码高亮,开始寻找相关的插件. 看到highlight.js,看到它主题样式如此之多,支持语言也如此之多,以为找到了神器.不想这只是痛苦的开始,为了让它支持HTML,我尝试 ...
- CodeBlocks配置pthread环境
参考资料:MinGW配置pthread环境 按[参考资料]里说的[下载资源]后,将libpthreadGC2.a放到codeBlocks安装目录下的MinGW\lib目录下,然后将pthread.h ...