ZOJ 2319 Beautiful People
LIS。先按S降序升序再按B降序排序(如果B不按降序排序的话就会覆盖掉正解),然后再对B用O(nlog(n))的LIS求解就可以了。用d数组标记每个元素在上升序列中的位置,然后根据d倒着找id就可以了。
#include<algorithm>
#include<iostream>
#include<cstring>
#include<fstream>
#include<sstream>
#include<cstdlib>
#include<vector>
#include<string>
#include<cstdio>
#include<bitset>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<set>
#define FF(i, a, b) for(int i=a; i<b; i++)
#define FD(i, a, b) for(int i=a; i>=b; i--)
#define REP(i, n) for(int i=0; i<n; i++)
#define CLR(a, b) memset(a, b, sizeof(a))
#define debug puts("**debug**")
#define LL long long
#define PB push_back
#define MP make_pair
using namespace std; const int N = 100100;
const int INF = 1e9 + 7; struct Node
{
int s, b, id;
bool operator < (const Node &rhs) const
{
return s < rhs.s || (s == rhs.s && b > rhs.b);
}
}p[N];
int g[N];
int d[N]; int main()
{
int s, b, t, n, ans;
scanf("%d", &t);
while(t --)
{
scanf("%d", &n);
for(int i = 0; i < n; i ++)
{
scanf("%d%d", &s, &b);
p[i].s = s, p[i].b = b, p[i].id = i + 1;
}
sort(p, p + n);ans = 0;
for(int i = 1; i <= n; i ++) g[i] = INF;
for(int i = 0; i < n; i ++)
{
int k = lower_bound(g+1, g+n+1, p[i].b) - g;
g[k] = p[i].b;
d[i] = k;
ans = max(ans, k);
}
printf("%d\n", ans);
int pt = -1;
for(int i = n - 1; i >= 0; i --)
{
if(p[i].s != pt && d[i] == ans)
{
printf("%d", p[i].id);
if(ans) putchar(' ');
ans --;pt = p[i].s;
}
if(!ans) break;
}puts("");
if(t) puts("");
}
}
ZOJ 2319 Beautiful People的更多相关文章
- I - Beautiful People ZOJ - 2319 (二分法)
The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...
- 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 ...
- zoj 2829 Beautiful Number
Beautiful Number Time Limit: 2 Seconds Memory Limit: 65536 KB Mike is very lucky, as he has two ...
- zoj 2850 Beautiful Meadow
Beautiful Meadow Time Limit: 2 Seconds Memory Limit: 65536 KB Tom's Meadow Tom has a meadow in ...
- ZOJ 2319 Beatuiful People(单调递增序列的变形)
Beautiful People Time Limit: 5 Seconds Memory Limit: 32768 KB Special Judge The most prest ...
- ZOJ 3213 Beautiful Meadow 简单路径 插头DP
简单路径的题目,其实就是在状态后面多记了有多少个独立插头. 分类讨论独立插头: 1.只存在上插头或者左插头,可以选择作为独立插头. 2.都不存在上插头和左插头,选择作为独立插头的同时要标号为新的连通块 ...
- ASC #1
开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...
- poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)
水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of ...
- ZOJ 2850和ZOJ 1414
下午上数据结构,结果竟然没有新题.T T果断上OJ来水一发 ZOJ 2850 Beautiful Meadow 传送门http://acm.zju.edu.cn/onlinejudge/showP ...
随机推荐
- CDOJ 1401 谭爷的黑暗沙拉 数学
谭爷的黑暗沙拉 题目连接: http://mozhu.today/#/problem/show/1401 Description 谭爷有\(n\)种不同种类的食材(水果&蔬菜),他想做出一份总 ...
- TYVJ 1463 智商问题 分块
TYVJ 1463 智商问题 Time Limit: 1.5 Sec Memory Limit: 512 MB 题目连接 http://www.tyvj.cn/p/1463 背景 各种数据结构帝~ ...
- redis缓存穿透解决办法--排它锁
- javascript小记-javascript运行机制
任何语言的运行过程中,都会有编译和执行: 对于传统编译型语言来说,编译步骤分为:词法分析.语法分析.语义检查.代码优化和字节生成.但对于解释型语言来说,通过词法分析和语法分析得到语法树后,就可以开始解 ...
- STM32 3.3V参考电压 TL431/MC1403/LM385
TL431作为一个高性价比的常用分流式电压基准,有很广泛的用途. 图(1)是TL431的典型接法,输出一个固定电压值,计算公式是: Vout = ( (R1+R2) / R2 ) * 2.5 V 同时 ...
- Javascript 面向对象编程(一):封装(转载)
Javascript是一种基于对象(object-based)的语言,你遇到的所有东西几乎都是对象.但是,它又不是一种真正的面向对象编程(OOP)语言,因为它的语法中没有class(类). 那么,如果 ...
- 【从零学习openCV】IOS7人脸识别实战
前言 接着上篇<IOS7下的人脸检測>,我们顺藤摸瓜的学习怎样在IOS7下用openCV的进行人脸识别,实际上非常easy,因为人脸检測部分已经完毕,剩下的无非调用openCV的方法对採集 ...
- Ext BoxComponent
Ext.BoxComponent也是一个比较重要的基础类,它直接继承自Ext.Component,并实现了定位和控制自身大小的功能. 可以使用pageX.pageY.x.y为Ext.BoxCompon ...
- https跳转到http的过程在IE6中存在BUG(Bea-090475)
前段时间做OA系统的https的安全登录功能(以前登录是采用的一般的http方式,后因为安全性考虑需要改成https的方式)在本机测试完全通过. 可是近期同事发现在测试环境下用IE6访问会出现不能访问 ...
- Kafka broker配置介绍 (四)
这部分内容对了解系统和提高软件性能都有很大的帮助,kafka官网上也给出了比较详细的配置详单,但是我们还是直接从代码来看broker到底有哪些配置需要我们去了解的,配置都有英文注释,所以每一部分是干什 ...