AC_Dream 1216 G - Beautiful People
题意:
有n个人每人有一个力气值Si,美丽值Bi,满足Bi>Bj&&Si>Sj 或者 Bi<Bj&&Si<Sj 的人可以
一起参见晚会,问最多有多少人可以一起参见晚会。
思路: 我们根据S从小到大将所有人排序,然后看B最长的上升子序列的长度求出来即可!
在排序中优先对S排序,S相等的则对B进行由大到小的排序,why?
也就是对于S相同的,我们先选取B最大的值插入LIS中,因为比如 S1=1, B1 = 1
S1=1, B1 = 2, S1=1, B1 = 3, 如果不进行排序,直接按照求B中的lis,显然长度
为3,显然是不对的,因为相同的S中只能选择一个B出来!所以就要对S相同的B进行
降序排序! 这样就变成了一个裸lis!
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#define N 100005
using namespace std; struct node{
int x, y;
int p;
}; bool cmp(node a, node b){
if(a.x == b.x)
return a.y > b.y;
return a.x < b.x;
} bool myCmp(node a, node b){
return a.y <= b.y;//这里要写成 <=;因为upper_bound返回的是“元素值 >插入值”
//最后一个插入值的位置,元素值 == 插入值的时候,默认 元素值
// >插入值,但在该题中,相等的情况下不能算在lis中的!
} node a[N];
node c[N]; int pre[N], path[N]; int main(){
int n;
while(scanf("%d", &n) != EOF){
for(int i=; i<n; ++i)
scanf("%d%d", &a[i].x, &a[i].y), a[i].p = i+; sort(a, a+n, cmp);
c[] = a[];
pre[] = ;
path[] = ;
int len = ; for(int i=; i<n; ++i){
int k = upper_bound(c, c+len, a[i], myCmp) - c;
pre[i] = k ? path[k-] : ;//当前插入节点i的位置为k,它的前一个(k-1位置)元素的序号!
path[k] = i;//当前插入k位置的节点的序号
c[k] = a[i];
if(k+ > len) len = k+;
}
int tmp = path[len-];
printf("%d\n", len);
printf("%d", a[path[len-]].p);
for(int i=len-; i >= ; --i){
tmp = pre[tmp];
printf(" %d", a[tmp].p);
}
printf("\n"); }
return ;
}
AC_Dream 1216 G - Beautiful People的更多相关文章
- ASC(1)G(上升时间最长的序列)
G - Beautiful People Time Limit: 10000/5000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
- Noj - 在线强化训练3
状态 题号 竞赛题号 标题 1091 A 求解逆波兰表达式(Calculate the reverse Polish notation) 1017 B 数列 1323 C 穷举n位二进制数 ...
- Storyboards Tutorial 03
这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...
- 文件图标SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...
- acd - 1216 - Beautiful People(DLIS)
意甲冠军:一个人有两个属性S, B(1 ≤ Si, Bi ≤ 10^9),当两个人满足这两个属性 S1 < S2 && B1 < B2 要么 S1 > S2 & ...
- ACdream 1216 (ASC训练1) Beautiful People(DP)
题目地址:http://acdream.info/problem? pid=1216 这题一開始用的是线段树.后来发现查询的时候还须要DP处理.挺麻烦..也就不了了之了..后来想到,这题事实上就是一个 ...
- ACdream 1216——Beautiful People——————【二维LIS,nlogn处理】
Beautiful People Special Judge Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (J ...
- hdu4888 Redraw Beautiful Drawings 最大流+判环
hdu4888 Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/6553 ...
- HDU4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
Redraw Beautiful Drawings Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
随机推荐
- 《软件性能测试与LoadRunner实战教程》新书上市
作者前三本书<软件性能测试与LoadRunner实战>.<精通软件性能测试与LoadRunner实战>和<精通软件性能测试与LoadRunner最佳实战>面市后,受 ...
- Mule ESB 社区版 企业版 资源下载 包含3.5和3.6
很多的资源官方已经没有提供下载了,我将资源上传到网盘,供大家下载和收藏 AnypointStudio-for-win-32bit-5.0.2-201502251307.ziphttp://pan.ba ...
- jinkins在windows上的安装 配置C#编译
首先jinkins在windows上的安装就不说,安装只需要下载相应安装包就可以了,后有些时候经常需要修改端口号.修改如下: 然后重启jenkins服务 首次运行界面 个人建议插件按需安装. 建立一个 ...
- GTD时间管理(3)---时间特区图
最近在网上看到一副时间特区图,想象非常深,特点想分享给大家. 从上图可以看出 说明一个人全天的状况 说明: 全天时段 状态 7:30-8:00 是处于起床,穿衣,刷牙,吃早餐 8:00-9:00 是处 ...
- jsp中表格,表格中的文字根据表格的大小自动换行
style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word" 语法: word-break : ...
- Codeforces Round #384 (Div. 2) A. Vladik and flights 水题
A. Vladik and flights 题目链接 http://codeforces.com/contest/743/problem/A 题面 Vladik is a competitive pr ...
- 关于VS2010出现“此方法显式使用的 CAS 策略已被 .NET Framework 弃用... ...请使用 NetFx40_LegacySecurityPolicy 配置开关”解决办法
有时候VS会出现“此方法显式使用的 CAS 策略已被 .NET Framework 弃用.若要出于兼容性原因而启用 CAS 策略,请使用 NetFx40_LegacySecurityPolicy 配置 ...
- web项目总结
web项目 Webroot下面的index.jsp页面的内容: <%@ page language="java" pageEncoding="UTF-8" ...
- iis,w3wp一直出现WerFault.exe应用程序错误
这个进程是Windows错误报告技术里的一个东西,来收集软件崩溃或者挂起后的数据然后向微软反馈报告.关闭系统的错误报告功能后看看 1:打开 运行 (热键:win+R)输入 gpedit.msc 打开 ...
- Promise 使用心得
this.testPromise=function(){ return new Promise(function(resolve,reject){ co ...