排序后贪心或根据第二关键字找最长下降子序列

#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的更多相关文章

  1. POJ 1065 Wooden Sticks / hdu 1257 最少拦截系统 DP 贪心

    参考链接:http://blog.csdn.net/xiaohuan1991/article/details/6956629 (HDU 1257 解题思路一样就不继续讲解) POJ 1065题意:给你 ...

  2. POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...

  3. HDU ACM 1051/ POJ 1065 Wooden Sticks

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. 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 ...

  5. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  6. POJ - 1065 Wooden Sticks(贪心+dp+最长递减子序列+Dilworth定理)

    题意:给定n个木棍的l和w,第一个木棍需要1min安装时间,若木棍(l’,w’)满足l' >= l, w' >= w,则不需要花费额外的安装时间,否则需要花费1min安装时间,求安装n个木 ...

  7. POJ 1065 Wooden Sticks(zoj 1025) 最长单调子序列

    POJ :http://poj.org/problem?id=1065 ZOJ: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId= ...

  8. 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 ...

  9. POJ 1065 Wooden Sticks【贪心】

    题意: 有一些木棍,每个有长度和重量,要求把这些木棍排成若干两个属性值均不下降的序列.问至少要分为多少个序列.且要保证排出来的子序列数最少. 思路: ( 9 , 4 ) ,( 2 , 5 ) ,( 1 ...

随机推荐

  1. android学习笔记53——自动朗读TTS

    自动朗读TTS android提供了自动朗读功能--其指的是支持可以对指定文本内容进行朗读,从而发出声音: 同时android的自动朗读支持还允许把文本对应的音频录制成音频文件,方便后续播放. 这种自 ...

  2. 实现远程连接ACCESS数据库的方法

    使用了TCP/IP,ADO及(需要安装Microsoft 4.0.).分服务器和客户端两部分,可以多用户同时连接.远程连接Access有很多方法,我以前已经比较详细的回答过(见下面所列的5种方法),我 ...

  3. 什么是BOM头,及PHP解决办法

    类似WINDOWS自带的记事本等软件,在保存一个以UTF-8编码的文件时,会在文件开始的地方插入三个不可见的字符(0xEF 0xBB 0xBF,即BOM).它是一串隐藏的字符,用于让记事本等编辑器识别 ...

  4. 用file上传文件时,浏览器返回值总是自动添加<pre>的解决办法

    在返回的JSon字符串里面总是莫名其妙的添加了<pre>标签,例如返回内容为"ok",在浏览器里面就变成了"<pre style="word- ...

  5. sql(转自http://www.imooc.com/article/2325)

    http://www.imooc.com/article/2325

  6. 含大量行的订单创建时候creditlimit校验最耗时间

    含大量行的订单创建时候creditlimit校验最耗时间

  7. python类及其方法

    python类及其方法 一.介绍 在 Python 中,面向对象编程主要有两个主题,就是类和类实例类与实例:类与实例相互关联着:类是对象的定义,而实例是"真正的实物",它存放了类中 ...

  8. Python全栈开发day3

    1.Pycharm使用介绍 1.1 新建py文件自动添加python和编码 1.2 更改pycharm默认字体和风格 点击左上角“file”-->“Settings”(或者用“Ctrl+Alt+ ...

  9. MySQL相关操作知识

    1.解决客户端联不上MySQL服务器的问题: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION; ...

  10. WebClient异步下载文件

    namespace ConsoleAppSyncDownload{    class Program    { static void Main(string[] args)        {     ...