poj3636
来源:互联网 发布:cpu 编程 英语 编辑:程序博客网 时间:2024/06/03 17:54
一道值得做的题目:LINK:http://poj.org/problem?id=3636
这道题运用到了dilworth定理,但是这里要注意的是原题目的严格的小于(不包含等于),因此第一个参数是按照升序的顺序来排列的,但是第二个元素,由于要求是严格的单调递增,因此在排序第二个元素的时候是按照降序的顺序来排列的,为什么这样做呢?是因为假如第一个参数相同的话,但是第二个参数不相同,但是我们要严格的小,因此降序帮组我们处理了这个问题。
同时初始的时候,不懂得优化,因此TLE了很多次,后面看了博文终于知道了,要用二分查找(nlogn)
AC CODE:
#include<stdio.h>#include<climits>#include<algorithm>#include<iostream>using namespace std;const int maxn=20010;typedef struct node{ int x,y;}node;node a[maxn];int f[maxn];int cmp(node a, node b){ return a.x<b.x||(a.x==b.x&&a.y>b.y);}int binarysearch(int l,int r,int x){ while(l<=r) { int m=(l+r)/2; if(x<=f[m]) l=m+1; else r=m-1; } return l;}void workstation(int n){ f[0]=a[0].y; int len=0; for(int i=1;i<n;i++) { int j=binarysearch(0,len,a[i].y); f[j]=a[i].y; if(j>len) { len=j; } } printf("%d\n",len+1);}int main(void){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d %d",&a[i].x,&a[i].y); } sort(a,a+n,cmp); workstation(n); }return 0;}
0 0
- poj3636
- POJ1065+POJ3636
- poj3636 Nested Dolls
- 【贪心】poj3636 nested dolls
- 贪心+偏序定理 poj1065+poj3636
- dilworth解决的题目poj3636,poj1631
- 【POJ3636】Nested Dolls Dilworth定理(偏序集定理二)
- POJ3636 Nested Dolls ACM解题报告(暴力贪心(也可用二分查找降低复杂度))
- 依次输出链表中的各个结点的递归算法
- Convert Sorted List to Binary Search Tree ---请叫我变形金刚(please call me a transformer)
- error LNK2005: _DllMain@12 already defined in xxx.OBJ
- IOS学习--Foundation--计算文件中得代码行数(小练习)
- easyui 月历
- poj3636
- mfc中如何取消组合框的排序
- 黑马培训IOS学习--Foundation---NSSet的使用
- asio学习笔记3
- hibernate注解之实体属性OneToOne 单双向关联(三)
- 黑马培训之IOS学习--Foundation--dictionary字典的使用
- UICollectionView 与 storyboard 的一点体会
- CI框架源码阅读笔记1 - 环境准备、基本术语和框架流程
- asio学习笔记4