Beautiful People

Special JudgeTime Limit: 10000/5000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others)

Problem Description

The most prestigious sports club in one city has exactly N members. Each of its members is strong and beautiful. More precisely, i-th member of this club (members being numbered by the time they entered the club) has strength Si and beauty Bi. Since this is a very prestigious club, its members are very rich and therefore extraordinary people, so they often extremely hate each other. Strictly speaking, i-th member of the club Mr X hates j-th member of the club Mr Y if Si <= Sj and Bi >= Bj or if Si >= Sj and Bi <= Bj (if both properties of Mr X are greater then corresponding properties of Mr Y, he doesn't even notice him, on the other hand, if both of his properties are less, he respects Mr Y very much).

To celebrate a new 2003 year, the administration of the club is planning to organize a party. However they are afraid that if two people who hate each other would simultaneouly attend the party, after a drink or two they would start a fight. So no two people who hate each other should be invited. On the other hand, to keep the club prestige at the apropriate level, administration wants to invite as many people as possible.

Being the only one among administration who is not afraid of touching a computer, you are to write a program which would find out whom to invite to the party.

Input

      The first line of the input file contains integer N — the number of members of the club. (2 ≤ N ≤ 100 000). Next N lines contain two numbers each — Si and Brespectively (1 ≤ Si, Bi ≤ 109).

Output

      On the first line of the output file print the maximum number of the people that can be invited to the party. On the second line output N integers — numbers of members to be invited in arbitrary order. If several solutions exist, output any one.

Sample Input

4
1 1
1 2
2 1
2 2

Sample Output

2
1 4

Source

Andrew Stankevich Contest 1
 
 
 
算法:最长上升子序列nlogn的解法(详情可以参见大白书P62),本题有一个不同的地方是,2个值都是严格递增(设为x,y),所以可根据x的值从小到大排序,这时我们从左往右只需考虑y的值因为x的值一定是递增的; 当x相同时根据y的值从大到小排序,为什么y要递减呢?因为当x相等时如果y为递增的话,那么选出的方案中就会将x相等的几个people都包含进去,显然是错的。然后我们就可以进行DP了,cnt[i]表示以第i个people结尾的最长上升子序列的长度,d[i]表示最长上升子序列长度为i时子序列末尾的最小y值(详见代码)。
本题还需要输出其中一种方案,我们只需根据DP得到的状态回溯输出就OK了。
 
 
 #include <iostream>
#include <memory.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define INF 1000000000
#define MAXN 100010
class CT
{
public:
int x,y,num;
bool operator <(const CT &c2)const
{
if(x!=c2.x)
return x<c2.x;
return y>c2.y;
}
}; CT a[MAXN];
int d[MAXN];
int cnt[MAXN]={};
int fa[MAXN]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
scanf("%d %d",&a[i].x,&a[i].y);
a[i].num=i;
}
sort(a+,a++n); d[]=;
fill_n(d+,n+,INF);
memset(cnt,,sizeof cnt);
memset(fa,-,sizeof fa);
int ans=; for(int i=;i<=n;i++)
{
int low=lower_bound(d,d+i,a[i].y)-d-;
cnt[i]=low+;
ans=max(ans,cnt[i]);
d[low+]=a[i].y;
} printf("%d\n",ans);
int u;
for(int i=n;i>=;i--)
if(cnt[i]==ans)
{
u=i;
break;
} printf("%d",a[u].num);
int pre=u;
for(int i=u-;i>=;i--)
{
if(a[i].y<a[pre].y && cnt[i]==cnt[pre]-)
{
printf(" %d",a[i].num);
pre=i;
}
}
printf("\n");
}
return ;
}

ZOJ3519-Beautiful People:最长上升子序列的变形的更多相关文章

  1. hdu5282 最长公共子序列的变形

    pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...

  2. DP专辑之最长公共子序列及其变形

    vijos1111(裸的最长公共子序列) 链接:www.vijos.org/p/1111 题解:好久没有写最长公共子序列了,这题就当是复习了.求出最长公共子序列,然后用两个单词的总长度减去最长公共子序 ...

  3. SGU 199 - Beautiful People 最长上升子序列LIS

    要邀请n个人参加party,每个人有力量值strength Si和魅力值 beauty Bi,如果存在两人S i ≤ S j and B i ≥ B j 或者  S i ≥ S j and B i ≤ ...

  4. 最长上升子序列的变形(N*log(N))hdu5256

    序列变换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  5. HDU 1080 Human Gene Functions - 最长公共子序列(变形)

    传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...

  6. ACM: 强化训练-Beautiful People-最长递增子序列变形-DP

    199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...

  7. hdu1503 最长公共子序列变形

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...

  8. hdu 1080 dp(最长公共子序列变形)

    题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G -  G ...

  9. SGU 199 Beautiful People 二维最长递增子序列

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20885 题意: 求二维最长严格递增子序列. 题解: O(n^2) ...

随机推荐

  1. Day02_VI基本操作及C基础

    2013年09月30日 星期一 09时37分03秒 回顾:     1. linux系统的知识背景     2. vi的使用 在正常模式下使用nyy可以把光标所在行开始的连续n行拷贝到剪贴板上去 在正 ...

  2. ubantu14.04 apache2 支持重写模式

    想要开启thinkphp的重写模式,apache必须.htaccess支持, 其他情况也有需要开启.htaccess支持的. 下面是ubantu开启方法: 0. .htaccess这个文件应该放在与入 ...

  3. [实战]挖掘CSRF姿势

    [-]CSRF是个什么鬼? |___简单的理解: |----攻击者盗用了你的身份,以你的名义进行某些非法操作.CSRF能够使用你的账户发送邮件,获取你的敏感信息,甚至盗走你的财产. |___CSRF攻 ...

  4. StoryBoard 设置TabBar SelectImage 和tintColor

    如图:StoryBoard 结构是 Tabbar + Navi + ViewController 需求:需要修改TabBar的Image 和SelectImage 设置Image 设置SelectIm ...

  5. tomcat端口占用后的解决办法

    学 习网页设计的同学都会用到tomcat这个软件,在安装的时候我们一般都会选择端口为8080端口,这个端口一般情况下是不会有程序占用的,所以我们运行 tomcat不会出现什么问题,但是如果一旦别占用, ...

  6. 浅谈C++中的那些内存泄露

    尽管学过C语言.可是C++里面的一些基础还是不太懂,还须要再掌握. 老范也開始要讲C++设计模式了,必须快点看了.不然就要白花窝滴钱了. 对于内存泄露,我的个人理解就是程序在执行过程中,自己开辟了空间 ...

  7. Welcome to Apache™ Hadoop®!

    What Is Apache Hadoop? Getting Started Download Hadoop Who Uses Hadoop? News 15 October, 2013: relea ...

  8. [React Testing] Conditional className with Shallow Rendering

    Often our components have output that shows differently depending on the props it is given; in this ...

  9. 记录一下自己总结出来的,在内网环境下使用maven打包的各种方法,包括各种常用的打包方式(一)

    (一)内外网代理仓库搭建 想了一下,先用这个MAVEN安装部署的说明随笔,作为自己的第一篇技术帖,往后会陆陆续续将自己研究的心得发出来,留下脚印.希望有大神可以指点 一 .文章主要解决问题说明 1) ...

  10. mysql主从监控

    要求:检测myslq从库状态,跳过固定的错误号,每隔30秒检测一次,如果符合条件自动跳过或者是重启从库 1)取出mysql从库的关键字 [root@localhost scripts]# mysql ...