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) ...
随机推荐
- windows下定时利用bat脚本实现ftp上传和下载
前言: 工作中可能会遇到以下情况,利用windows作为中转,来实现两台linux服务器的文件传输. 实现步骤: 1.FTP上传和下载的bat脚本. 脚本分为两部分:可执行bat脚本和ftp命令文件: ...
- 验证合法的url
package test; import java.util.regex.Matcher;import java.util.regex.Pattern; public class Test { pub ...
- Demon_Tank (坦克移动发射子弹)
using UnityEngine; using System.Collections; public class Tank : MonoBehaviour { //子弹预设体 public Game ...
- [每日一题] 11gOCP 1z0-052 :2013-09-3 Because of frequent checkpoints...........................A30
转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/11022433 正确答案:BC 这里我就偷一下懒了,引用 http://www.itpub. ...
- Linux字符设备驱动
一.字符设备基础 字符设备 二.字符设备驱动与用户空间访问该设备的程序三者之间的关系 三.字符设备模型 1.Linux内核中,使用 struct cdev 来描述一个字符设备 动态申请(构造)cdev ...
- android studio 更改快捷键为eclipse中习惯的方式
虽然之前看了不少android studio的快捷键,但主要开发依然还是在eclipse上,仍然不习惯android studio的快捷键方式,今天看一视频说可以改快捷键为eclipse的方式,不由得 ...
- linux wc命令
Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...
- JAVA--聊天界面面板
package windows.beautify; import java.awt.BorderLayout; import java.awt.Color; import java.awt.event ...
- shell中的eval
eval语法 eval arg1 arg2 ... eval的作用就是将后面的参数arg1 arg2等等当成一个pipeline,然后重新执行shell处理pipeline的流程(有关pipeline ...
- 关于 HRESULT:0x80070
异常来自 HRESULT:0x80070057 (E_INVALIDARG) 网上看的普遍办法是: 解决方法 是 删除 C:/WINDOWS/Microsoft.NET/Framework/v2.0. ...