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. java笔记4之比较运算符

    /*    比较运算符:        ==,!=,>,>=,<,<=            特点:        无论你的操作是简单还是复杂,结果是boolean类型.   ...

  2. linux 切换用户之后变成-bash-x.x$的解决方法

    我们平时在linux下切换用户后命令行为什么会变成-bash-3.2$呢,我们来分析一下,这就是跟linux的机制有关联了,因为在linux下每次通过useradd创建新的用户时,都会将所有的配置文件 ...

  3. JavaWeb:基于MVC设计模式的一个小案例(一)

    (未经允许,请勿转载,谢谢.) 本案例的处理过程: 客户端发送一个请求给服务器,服务器把这个请求给Servlet,Servlet 获取请求信息,根据请求信息的情况去调用 model (在这里是一个普通 ...

  4. 查询死锁和处理死锁(SqlServer)

    -------------------查询死锁,极其引起的原因-------------------------------use master go create procedure sp_who_ ...

  5. MVC VIEW 时间格式控制

    @Convert.ToDateTime(Model.CheckPatronExclusionResults.RequestTime).ToString("yyyy-MM-dd HH:mm:s ...

  6. 【自学iOS攻略】了解有什么新技术的途径

    1.了解有什么新技术1> 苹果API文档 - General - Guides - iOSx API Diffs2> 观看WWDC会议视频 2.如何使用新技术1> 自己根据API文档 ...

  7. LIB文件和DLL文件的作用

    (1)lib是编译时需要的,dll是运行时需要的.如果要完成源代码的编译,有lib就够了.如果也使动态连接的程序运行起来,有dll就够了.在开发和调试阶段,当然最好都有.(2)一般的动态库程序有lib ...

  8. GitHub 小试

    GitHub是什么? 它是用来进行版本控制的,就是用来保存项目的地方. 但是项目要是运行,还是需要你本地的环境,它只不过是用来保存代码罢了. GitHub如何操作? 可以通过客户端进行代码提交,更新. ...

  9. 解决蛋疼的阿里云单CPU使用率的问题。

    工作中涉及到阿里云的应用.在性能测试阶段,压测过程中只要一个CPU未使用满,第二个CPU以至于第三个和第四个CPU完全用不到. 后来和阿里云的同事沟通他们现在用的是单队列的网卡,只能靠RPS/RFS这 ...

  10. Webstorm10.0.3破解程序及汉化包下载、Webstorm配置入门指南

    核心提示: WebStorm 是jetbrains公司旗下一款JavaScript 开发工具.被广大中国JS开发者誉为“Web前端开发神器”.“最强大的HTML5编辑器”.“最智能的JavaSscri ...