[SGU 199] Beautiful People

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 S i and beauty B i . 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 S i ≤ S j and B i≥ B j or if S i ≥ S j and B i ≤ B j (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 presti≥ 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 — S i and B irespectively ( 1 ≤ S i, B i ≤ 10 9 ).

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 test(s)

Input


1 1 
1 2 
2 1 
2 2

Output


1 4

作为经典比赛中的一道题,想必这一定是重点的重点,那就写博记录一下.

题解:

本题虽有两个奇怪的不等式,事实上就是求最长上升子序列(读者可以想想为什么)

于是,先对两个序列排序,排序规则是第二关键字从大到小,第一关键字从小到大

然后我们就有了一个正常做lis的序列

但是因为要nlogn内完成,所以还需要二分或者树状数组优化,那么我这里只讲二分的方法,另一种留给读者去思考

首先你必须得会二分求lis,不然学习一下这个http://blog.csdn.net/wall_f/article/details/8295812

那么接下来就方便了,你只需要此时二分出第二关键字比a[i]小的最大的答案,如果他比最大的还大,那么把它加到二分序列中

同时记录下这一位是由哪一个数推过来的,即是最后所要的答案

 #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n,ans=,pre[],s[];
struct xint{int x,y,num;}a[];
bool cmp(xint x,xint y){return x.x==y.x?x.y<y.y:x.x<y.x;}
int main(){
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+,cmp);
for (int i=;i<=n;++i){
int l=,r=ans;
while (l<r){
int mid=l+(r-l+)/;
if (a[s[mid]].y>=a[i].y) r=mid-; else l=mid;
}
int res=l+; pre[i]=s[res-];
if (a[i].y<a[s[res]].y||s[res]==) s[res]=i;
ans=max(ans,res);
}
printf("%d\n",ans);
for (int i=s[ans];i;i=pre[i]) printf("%d ",a[i].num);
}

[SGU 199] Beautiful People的更多相关文章

  1. SGU 199 Beautiful People(DP+二分)

    时间限制:0.25s 空间限制:4M 题意: 有n个人,每个人有两个能力值,只有一个人的两个能力都小于另一个的能力值,这两个人才能共存,求能同时共存的最大人数. Solution: 显然这是一个两个关 ...

  2. 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 ≤ ...

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

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

  4. Beautiful People SGU - 199 ZOJ - 2319

    最长上升子序列O(n log n):http://www.cnblogs.com/hehe54321/p/cf-340d.html 题目:https://cn.vjudge.net/problem/Z ...

  5. SGU题目总结

    SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...

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

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

  7. 使用Beautiful Soup编写一个爬虫 系列随笔汇总

    这几篇博文只是为了记录学习Beautiful Soup的过程,不仅方便自己以后查看,也许能帮到同样在学习这个技术的朋友.通过学习Beautiful Soup基础知识 完成了一个简单的爬虫服务:从all ...

  8. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup

    开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...

  9. Python爬虫学习(11):Beautiful Soup的使用

    之前我们从网页中提取重要信息主要是通过自己编写正则表达式完成的,但是如果你觉得正则表达式很好写的话,那你估计不是地球人了,而且很容易出问题.下边要介绍的Beautiful Soup就可以帮你简化这些操 ...

随机推荐

  1. Kail更新源、输入法、浏览器

    更新源 kali官方的更新源:图中的kali-rolling是kali目前最新的代号,kali有两个代号(codename):sana和kali-rolling: 查看自己的kali linux源版本 ...

  2. scrapy框架的日志等级和请求传参, 优化效率

    目录 scrapy框架的日志等级和请求传参, 优化效率 Scrapy的日志等级 请求传参 如何提高scripy的爬取效率 scrapy框架的日志等级和请求传参, 优化效率 Scrapy的日志等级 在使 ...

  3. echarts demo

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. OSI七层参考模型每一层都有哪些协议

    OSI七层参考模型每一层都有哪些协议 第七层应用层 协议:DHCP • DNS • FTP • Gopher • HTTP • IMAP4 • IRC • NNTP • XMPP • POP3 • S ...

  5. hpu第六次周赛Problem F

    Problem F Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  6. 络谷 P1363 幻想迷宫

    P1363 幻想迷宫 题目描述 背景 Background (喵星人LHX和WD同心协力击退了汪星人的入侵,不幸的是,汪星人撤退之前给它们制造了一片幻象迷宫.) WD:呜呜,肿么办啊…… LHX:mo ...

  7. 循环A表,根据查询结果,更新A表字段

    create or replace procedure prc_user_xtzx_match(p_flag out varchar2) IS xingming_match_loginname ); ...

  8. Spring MVC-集成(Integration)-生成Excel示例(转载实践)

    以下内容翻译自:https://www.tutorialspoint.com/springmvc/springmvc_excel.htm 说明:示例基于Spring MVC 4.1.6. 以下示例显示 ...

  9. iOS:让64位兼容百度地图

    当使用了百度地图sdk的app在64位机中运行时,会出现No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_6 ...

  10. linux下环境变量C_INCLUDE_PATH

    环境变量定义一般都是/etc/profile文件(对所有用户有效),或者在Home目录下的.bashrc或.profile(只对当前用户有效)一般系统安装了编译工具之后无需设置这些变量编译都不会出现问 ...