Beautiful People

Special Judge Time Limit: 2000/1000MS (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 Bi respectively (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
 
 
题目大意:给你n个人,每个人有两个能力ai,bi。如果两个人的ai>=aj&&bi<=bj或ai<=aj&&bi>=bj的时候,他们两个会有仇恨。现在给你n个人的能力值,问你最多能邀请多少个人去聚会,且任意两人之间没有仇恨。
 
解题思路:要使每个人之间都没有仇恨的话,那么保证ai<aj&&bi<bj即可。那么我们可以首先将a能力排序,从小到大,如果a能力相同的时候,我们保证b能力大的排在前面,不然在endminv数组中的值会发生错误替换,模拟下面给的样例就知道为什么要排序b能力了。然后只需要在b能力上进行LIS操即可。这里用的是nlogn的LIS写法。LCS也有nlogn的写法,其实就是转化成求LIS的。
 
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
const int maxn=1e5+200;
const int INF = 0x3f3f3f3f;
int dp[maxn],endminv[maxn]; //dp[i]表示以i结尾的最长递增子序列长度 //endminv[i]表示LIS长度为i时,LIS结尾的最小值是多少
int path[maxn];
struct Number{
int x,y,idx;
}numbers[maxn];
bool cmp(Number a,Number b){
if(a.x==b.x)
return a.y>b.y; //必须有这个排序,下面那个样例就卡这里不排序的写法
return a.x<b.x;
}
int BinSearch(int l,int r,int key){ //二分查找大于等于key的第一个位置(下界)
int md;
while(l<r){
md=(l+r)/2;
if(endminv[md]>key){
r=md;
}else if(endminv[md]<key){
l=md+1;
}else{
return md;
}
}
return l;
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++){
scanf("%d%d",&numbers[i].x,&numbers[i].y);
numbers[i].idx=i;
}
sort(numbers+1,numbers+1+n,cmp);
memset(endminv,INF,sizeof(endminv));
int len=1,x,maxv=0;
for(int i=1;i<=n;i++){
x=BinSearch(1,n,numbers[i].y);
endminv[x]=numbers[i].y;
if(x>=len){
len++;
}
dp[i]=x;
}
len = len -1;
printf("%d\n",len);
int i,minx=INF,miny=INF;
int fir=1;
for(i=n;i>=1;i--){
if(dp[i]==len){
if(numbers[i].x<minx&&numbers[i].y<miny){
len--;
minx=numbers[i].x;
miny=numbers[i].y;
if(fir){
fir=0;
}else printf(" ");
printf("%d",numbers[i].idx);
}
}
}
}
return 0;
} /*
5
1 3
2 6
3 1
3 2
3 3 */

  

 
 
 

ACdream 1216——Beautiful People——————【二维LIS,nlogn处理】的更多相关文章

  1. HDU 1160 FatMouse's Speed(要记录路径的二维LIS)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. BZOJ2244: [SDOI2011]拦截导弹(CDQ分治,二维LIS,计数)

    Description 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度.并且能够拦截任意速度的导弹,但是以后每一发炮弹都不能高 ...

  3. 二维LIS(CDQ分治)

    题目描述 给定一个长度为N的序列S,S的每个元素pi是一个二元组(xi,yi),定义pi<pj当且仅当xi<xj并且yi<yj,求S的最长上升子序列长度 输入格式 第一行一个N,表示 ...

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

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

  5. 三维偏序-二维LIS

    Another Longest Increasing Subsequence Problem 有两种思路. 思路一: 考虑到如果只有一维,那么可以用f[s]表示长度为s时,最后一个数是多少,把这个想法 ...

  6. HDU 1025 Constructing Roads In JGShining's Kingdom(二维LIS)

    Constructing Roads In JGShining's Kingdom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65 ...

  7. SGU 521 North-East ( 二维LIS 线段树优化 )

    521. "North-East" Time limit per test: 0.5 second(s)Memory limit: 262144 kilobytes input: ...

  8. 二路单调自增子序列模型【acdream 1216】

    题目:acdream 1216 Beautiful People 题意:每一个人有两个值,能力值和潜力值,然后要求一个人的这两个值都严格大于第二个人的时候,这两个人才干呆在一块儿,给出很多人的值,求最 ...

  9. Comet OJ - Contest #6 B.双倍快乐(二维最大上升子序列和)

    双倍快乐 题目描述 Illyasviel:"你想要最长不下降子序列吗?" star-dust:"好啊!" Illyasviel:"老板,给我整两个最长 ...

随机推荐

  1. C#使用NPOI将DataGridView内数据写入电子表格Excel

    NPOI能够在用户没有安装office的情况下读写office文件,包括.xls/.doc/.ppt等类型的文件.本文介绍的是使用NPOI库内的函数读写Excel(.xls)内的内容.在使用NPOI之 ...

  2. jquery easyui 推荐博客 (MVC+EF+EasyUI+Bootstrap)

    构建ASP.NET MVC5+EF6+EasyUI 1.4.3+Unity4.x注入的后台管理系统(52)-美化EasyUI皮肤和图标   系列目录 我很久以前就想更新系统的皮肤功能,Easyui 自 ...

  3. 4.JasperReports学习笔记4-查询数据库生成动态的报表(WEB)

    转自:http://www.blogjava.net/vjame/archive/2013/10/12/404908.html 第一种方式: sql语句中定义查询条件,报表中定义接收参数 第二种方式: ...

  4. 【java并发编程艺术学习】(四)第二章 java并发机制的底层实现原理 学习记录(二) synchronized

    章节介绍 本章节主要学习 Java SE 1.6 中为了减少获得锁 和 释放锁 时带来的性能消耗 而引入的偏向锁 和 轻量级锁,以及锁的存储结构 和 升级过程. synchronized实现同步的基础 ...

  5. linux命令-gzip压缩

    把很大的目录/文件压缩成更小的文件,传输节省带宽,从服务端到客户端下载过程节省时间,减少带宽,节省使用率.使用cpu的资源. 压缩命令gzip [root@wangshaojun ~]# ls111. ...

  6. route-显示并设置Linux内核中的网络路由表

    route命令 网络配置 route命令用来显示并设置Linux内核中的网络路由表,route命令设置的路由主要是静态路由.要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或者同时位于两 ...

  7. ASE分析

    1.Prepare necessary input files(可以参考上次的博客http://www.cnblogs.com/renping/p/7391028.html) 1)对fq1和fq2合并 ...

  8. 1.8 收集的XSS Payload

    收集的XSS Payload ,可以做成字典,到时候批量测试:--------------------------------------------------------------------- ...

  9. jeecms v8 网站访问量配置

    <script src="${resSys}/jquery.js" type="text/javascript"></script> & ...

  10. 安装mysql8.0.11及修改root密码、连接navicat for mysql的思路详解

    1.1. 下载: 官网下载zip包,我下载的是64位的: 下载地址:https://dev.mysql.com/downloads/mysql/ 下载zip的包: 下载后解压:(解压在哪个盘都可以的) ...