[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. BZOJ 1941: [Sdoi2010]Hide and Seek KDtree + 估价函数

    Code: #include<bits/stdc++.h> #define maxn 200000 #define inf 1000000000 using namespace std; ...

  2. SweetAlert弹出框

    以前也用过,那个时候没有写过,突然看见了,就写上了. 网址:http://mishengqiang.com/sweetalert2/ swal({ title: '确定删除吗?', text: '你将 ...

  3. 【Apache Kafka】一、Kafka简介及其基本原理

      对于大数据,我们要考虑的问题有很多,首先海量数据如何收集(如Flume),然后对于收集到的数据如何存储(典型的分布式文件系统HDFS.分布式数据库HBase.NoSQL数据库Redis),其次存储 ...

  4. 非常简单的Python HTTP服务

    如果你急需一个简单的Web Server,但你又不想去下载并安装那些复杂的HTTP服务程序,比如:Apache,ISS等.那么, Python 可能帮助你.使用Python可以完成一个简单的内建 HT ...

  5. odoo widget 标签介绍

    widget="statusbar" 头部状态条标签 widget="email" 电子邮件地址标签 widget="selection" ...

  6. js数组对象排序详解

    一.js对象遍历输出的时候真的是按照顺序输出吗? 下边就来实践一下: var obj={'3':'ccc',name:'abc',age:23,school:'sdfds',class:'dfd',h ...

  7. CodeForcesGym 100735D Triangle Formation

    Triangle Formation Time Limit: Unknown ms Memory Limit: 65536KB This problem will be judged on CodeF ...

  8. vs2005添加include lib文件目录

    vs2005添加include lib文件目录 http://blog.sina.com.cn/s/blog_79489160010145wb.html 1. 添加编译所需要的 lib 文件 [解决方 ...

  9. 用R语言 画条形图(基于ggplot2包)

    1.用qplot(x,data=data,geom.=”bar”,weight=y)+scale_y_continuous("y")画出y关于x的条形. 图中提示binwidth这 ...

  10. spring-cloud-feign使用@RequetParam错误:QueryMap parameter must be a Map: int

    错误: QueryMap parameter must be a Map: int spring-cloud-feign处理@RequestParam和Spring MVC的不一样,Spring MV ...