[SGU 199] Beautiful People
[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
4
1 1
1 2
2 1
2 2
Output
2
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的更多相关文章
- SGU 199 Beautiful People(DP+二分)
时间限制:0.25s 空间限制:4M 题意: 有n个人,每个人有两个能力值,只有一个人的两个能力都小于另一个的能力值,这两个人才能共存,求能同时共存的最大人数. Solution: 显然这是一个两个关 ...
- 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 ≤ ...
- SGU 199 Beautiful People 二维最长递增子序列
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20885 题意: 求二维最长严格递增子序列. 题解: O(n^2) ...
- 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 ...
- SGU题目总结
SGU还是个不错的题库...但是貌似水题也挺多的..有些题想出解法但是不想写代码, 就写在这里吧...不排除是我想简单想错了, 假如哪位神犇哪天发现请告诉我.. 101.Domino(2015.12. ...
- ACM: 强化训练-Beautiful People-最长递增子序列变形-DP
199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...
- 使用Beautiful Soup编写一个爬虫 系列随笔汇总
这几篇博文只是为了记录学习Beautiful Soup的过程,不仅方便自己以后查看,也许能帮到同样在学习这个技术的朋友.通过学习Beautiful Soup基础知识 完成了一个简单的爬虫服务:从all ...
- 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup
开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...
- Python爬虫学习(11):Beautiful Soup的使用
之前我们从网页中提取重要信息主要是通过自己编写正则表达式完成的,但是如果你觉得正则表达式很好写的话,那你估计不是地球人了,而且很容易出问题.下边要介绍的Beautiful Soup就可以帮你简化这些操 ...
随机推荐
- Linux cat 命令
cat命令是linux下的一个文本输出命令,通常是用于观看某个文件的内容的:cat主要有三大功能:1.一次显示整个文件.$ cat filename2.从键盘创建一个文件.$ cat > ...
- 利用open MP获取计算机核心数量的方法
openMP是一款普遍通用的并行计算编程模型,使用它通常能够充分利用多核计算的优势. 以下是一种能够测试核心数量的方法: std::cout << "parallel begin ...
- MySQL之视图、触发器、存储过程、函数、事务、数据库锁
一.视图 视图:是一个虚拟表,其内容由查询定义.同真实的表一样,视图包含一系列带有名称的列和行数据. 视图的特点: 1.视图的列可以来自不同的表,是表的抽象和逻辑意义上建立的新关系: 2.视图是由基本 ...
- 《hello-world》第八次团队作业:Alpha冲刺-Scrum Meeting 3
项目 内容 这个作业属于哪个课程 2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 实验十二 团队作业8:软件测试与Alpha冲刺 团队名称 <hello--worl ...
- java 常见问题
1.Cannot convert value '0000-00-00 00:00:00' from column 1 to TIMESTAMP 2.怎么解决BigDecimal里面无限循环小数的问题啊 ...
- 【Codeforces 1106D】Lunar New Year and a Wander
[链接] 我是链接,点我呀:) [题意] 让你遍历n个节点,访问过的节点不操作. 如果是没有访问过的点,那就把它加到序列的末尾. 问你形成的最小字典序的序列是多少. [题解] 显然每次找最小的标号 用 ...
- NEMA-0183(GPRMC GPGGA)详细解释
NEMA-0183(GPRMC GPGGA)详细解释 nmea数据如下: $GPGGA,121252.000,3937.3032,N,11611.6046,E,1,05,2.0,45.9,M,-5. ...
- Colored Sticks (并查集+Trie + 欧拉路)
Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 37340 Accepted: 9796 Description You ...
- tomcat理解
- java.text.ParseException: Unparseable date: "2015-06-09 hh:56:19"
1.错误描写叙述 [DEBUG:]2015-06-09 16:56:19,520 [-------------------transcation start!--------------] java. ...