ZOJ3519-Beautiful People:最长上升子序列的变形
Beautiful People
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
Output
Sample Input
4
1 1
1 2
2 1
2 2
Sample Output
2
1 4
Source
#include <iostream>
#include <memory.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define INF 1000000000
#define MAXN 100010
class CT
{
public:
int x,y,num;
bool operator <(const CT &c2)const
{
if(x!=c2.x)
return x<c2.x;
return y>c2.y;
}
}; CT a[MAXN];
int d[MAXN];
int cnt[MAXN]={};
int fa[MAXN]; int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int n;
while(~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); d[]=;
fill_n(d+,n+,INF);
memset(cnt,,sizeof cnt);
memset(fa,-,sizeof fa);
int ans=; for(int i=;i<=n;i++)
{
int low=lower_bound(d,d+i,a[i].y)-d-;
cnt[i]=low+;
ans=max(ans,cnt[i]);
d[low+]=a[i].y;
} printf("%d\n",ans);
int u;
for(int i=n;i>=;i--)
if(cnt[i]==ans)
{
u=i;
break;
} printf("%d",a[u].num);
int pre=u;
for(int i=u-;i>=;i--)
{
if(a[i].y<a[pre].y && cnt[i]==cnt[pre]-)
{
printf(" %d",a[i].num);
pre=i;
}
}
printf("\n");
}
return ;
}
ZOJ3519-Beautiful People:最长上升子序列的变形的更多相关文章
- hdu5282 最长公共子序列的变形
pid=5282">http://acm.hdu.edu.cn/showproblem.php?pid=5282 Problem Description Xuejiejie loves ...
- DP专辑之最长公共子序列及其变形
vijos1111(裸的最长公共子序列) 链接:www.vijos.org/p/1111 题解:好久没有写最长公共子序列了,这题就当是复习了.求出最长公共子序列,然后用两个单词的总长度减去最长公共子序 ...
- 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 ≤ ...
- 最长上升子序列的变形(N*log(N))hdu5256
序列变换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 1080 Human Gene Functions - 最长公共子序列(变形)
传送门 题目大意: 将两个字符串对齐(只包含ACGT,可以用'-'占位),按照对齐分数表(参见题目)来计算最后的分数之和,输出最大的和. 例如:AGTGATG 和 GTTAG ,对齐后就是(为了表达对 ...
- ACM: 强化训练-Beautiful People-最长递增子序列变形-DP
199. Beautiful People time limit per test: 0.25 sec. memory limit per test: 65536 KB input: standard ...
- hdu1503 最长公共子序列变形
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1503 题意:给出两个字符串 要求输出包含两个字符串的所有字母的最短序列.注意输出的顺序不能 ...
- hdu 1080 dp(最长公共子序列变形)
题意: 输入俩个字符串,怎样变换使其所有字符对和最大.(字符只有'A','C','G','T','-') 其中每对字符对应的值如下: 怎样配使和最大呢. 比如: A G T G A T G - G ...
- SGU 199 Beautiful People 二维最长递增子序列
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20885 题意: 求二维最长严格递增子序列. 题解: O(n^2) ...
随机推荐
- Gradle[0]依赖本地JAR和远程仓库JAR的配置
1.对本地Jar的依赖配置 如果不知道Jar包的远程仓库地址,而项目中又要使用该Jar包,就需要进行本地设置. 例如,需要使用的Jar包为sigar.jar,则需要在项目根目录下建目录:libs,并把 ...
- Javascript:getElementsByClassName
背景: 由于原生的getElementsByClassName不支持在指定标签中查找指定元素为指定class的情况,所以,这里舍弃了原生的方法调用 方法一: function getElement ...
- 高性能 Socket 组件 HP-Socket v3.2.1-RC4 公布
HP-Socket 是一套通用的高性能 TCP/UDP Socket 组件,包括服务端组件.client组件和 Agent 组件,广泛适用于各种不同应用场景的 TCP/UDP 通信系统,提供 C/C+ ...
- 常用语言api语法Cheat Sheet
http://overapi.com/jquery/ OverAPI.com Python jQuery NodeJS PHP Java Ruby Javascript ActionScript CS ...
- 2013国内IT行业薪资对照表【技术岗】
(本文为转载,具体出处不详) 说薪水,是所有人最关心的问题.我只 想说如果想在薪水上面满意,在中国,没有哪里比垄断国企好.电力.烟草.通信才是应该努力的方向.但是像我们这种搞研发的进IT行业似乎是注定 ...
- Win7 64位下配置Qt5.3和Wincap
最近在学网络编程,想在windows下用Qt做个网络抓包工具,就要用到WinPcap,而我的电脑的系统是Win7 64位,qt版本是Qt 5.3.1 for Windows 64-bit ( ...
- RPC 实现
PC,即 Remote Procedure Call(远程过程调用),说得通俗一点就是:调用远程计算机上的服务,就像调用本地服务一样. RPC 可基于 HTTP 或 TCP 协议,Web Servic ...
- apache ab工具对网站进行压力测试
Apache -- ab工具主要测试网站的(并发性能) 这个工具非常的强大. 基本语法 : cmd>ab.exe –n 请求总次数 -c 并发数 请求页面的url 进入到ab.ex ...
- 纯js滑动脚本
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- UML基础知识
UML:Unified Modeling Language,即统一建模语言.是一种图形化的建模语言标准. 如上图,UML可以帮助我们做软件需求分析和软件设计两方面的工作,在不同的应用场景中,UML的一 ...