[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. CPU 指令集(Instruction Set Architecture, ISA)

    本文摘自网络 概念 指令集是存储在CPU内部,对CPU运算进行指导和优化的硬程序,用来引导CPU进行加减运算和控制计算机操作系统的一系列指令集合.拥有这些指令集,CPU就可以更高效地运行.系统所下达的 ...

  2. iptables详解(4):iptables匹配条件总结之一

    所属分类:IPtables  Linux基础 在本博客中,从理论到实践,系统的介绍了iptables,如果你想要从头开始了解iptables,可以查看iptables文章列表,直达链接如下 iptab ...

  3. My97DatePicker 开始日期不能大于 结束日期

    My97DatePicker 日期控制,开始时间不能>结束时间,结束时间不能<开始时间 <li>日期:<input type="text" style ...

  4. MySQL的分组和排序

    分组操作 select count(id) from userinfo group by pat(id); -- 聚合函数: --count --max --sum --avg ---如果对于二次函数 ...

  5. BZOJ 1602 牧场行走

    直接写一波Lca就好了 #include<cstdio> #include<cmath> #include<algorithm> using namespace s ...

  6. [cf 599C] Day at the Beach

    题意:有n个数,将其分组使整个数列排序后每组中的数仍在该组中,求最多的分组数. 代码很易懂 #include <iostream> #include <algorithm> # ...

  7. 用Grails写单元测试

    新的领域,多练练,这样写出的程序,确实坚固些. 也要理解集成测试与数据库相关,单元测试与类方法有关. 如果测试文件没有建立,按如下操作: Unit tests are generated automa ...

  8. nyoj_38_布线问题_201403121753

    布线问题 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 南阳理工学院要进行用电线路改造,现在校长要求设计师设计出一种布线方式,该布线方式需要满足以下条件:1.把所有 ...

  9. django book chapter 2

    Django’s optional GIS (Geographic Information Systems) support requires Python 2.5 to 2.7. 这里提到了djan ...

  10. 申请Letencrypt的免费证书文件-nginx

    1.前言 Let's Encrypt是国外一个公共的免费SSL项目,由 Linux 基金会托管,它的来头不小,由Mozilla.思科.Akamai.IdenTrust和EFF等组织发起,目的就是向网站 ...