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 ...
随机推荐
- bzoj 1176: [Balkan2007]Mokia&&2683: 简单题 -- cdq分治
2683: 简单题 Time Limit: 50 Sec Memory Limit: 128 MB Description 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要 ...
- RN生命周期
网上看的博客,看着写的很好,想深入学RN的详细看下之后,再自己敲敲吧!有助于身体健康! 一个RN组件从它被加载,到最终被卸载会经历一个完整的生命周期.所谓生命周期,就是一个对象从开始生成到最后消亡所经 ...
- 反射生成SQL语句入门
今天我们来学习学习通过反射技术来生成SQL语句. 反射提供了封装程序集.模块和类型的对象.您可以使用反射动态地创建类型的实例,将类型绑定到现有对象,或从现有对象中获取类型.然后,可以调用类型的方法或访 ...
- IntelliJ IDEA代码分屏显示
- OpenCV/CUDA/Qt 环境配置小结
OpenCV Qt CUDA windows环境下 配置 反复装过几次,每次都网搜攻略:自个做个记录 方便以后使用. 碰到OpenCV各种奇怪的错误 先看看 图片imread() 有没有读空 再找其他 ...
- HDU 4726 Kia's Calculation(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 使用注册表优化终端、编辑器的中英字体混合显示,如「Consolas + 雅黑」「Monaco + 雅黑」
在终端.cmd.编辑器中偶尔会有中文字符出现,Windows下默认的点阵字体「宋体」和等宽英文字符放在一起非常违和.一个解决方法是下载混合字体,比如「Consolas + YAHEI hybrid」, ...
- mysql安装三 linux源码安装mysql5.6.22
http://blog.csdn.net/beiigang/article/details/43053803
- PostgreSQL 资源
http://blog.163.com/digoal@126/blog/static/163877040201172183022203/ http://m.oschina.net/u/2426299? ...
- 使用Bootstrap 3开发响应式网站实践04,使用Panels展示内容
在Bootstrap页面中,通常用Panels来展示主要功能的内容.该部分Html为: <div class="row" id="featureHeading&qu ...