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 ...
随机推荐
- ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力
C. Om Nom and Candies Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/526 ...
- Tasker to create toggle widget for ES ftp service -- Send Intent
To perform this mission, Tap the tab "tasks" of Tasker, create a task as below.Task: (ES F ...
- 求平方根C++
求平方根,正根.曾经都不会.昨天看数学,看到了,写了出来.自己又小优化了一下,非常不错. // squareRoot.cpp -- 2011-08-29-01.04 #include "st ...
- golang 关键字以及简单用法说明
golang只有25个关键字 package: 定义包名, go中任何一个文件必须有一个package, 一般而言,package的定义和文件所属文件夹一致, 并且main函数所在文件的package ...
- 深入理解 Java中的 流 (Stream)
首先,流是什么? 流是个抽象的概念.是对输入输出设备的抽象,Java程序中,对于数据的输入/输出操作都是以"流"的方式进行.设备能够是文件,网络,内存等. 流具有方向性,至于是输入 ...
- java classpath作用
环境变量的配置: 1):永久配置方式:JAVA_HOME=%安装路径%\Java\jdk path=%JAVA_HOME%\bin 2):临时配置方式:set path=%path%;C:\Progr ...
- [Shell学习笔记] 命令行下的高级网络工具cURL命令
原文: http://www.1987.name/365.html Linux curl命令是一个利用URL规则在命令行下工作的文件传输工具.它支持文件的上传和下载,所以是综合传输工具,但按传统,习惯 ...
- 4. python 修改字符串实例总结
4. python 修改字符串实例总结 我们知道python里面字符串是不可原处直接修改的,为了是原来的字符串修改过来,我们有一下方法: 1.分片和合并 >>> a='abcde' ...
- Android跳转各种系统设置界面-总结
来自:http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2017/0921/8536.html View btn1 = this.findVi ...
- arcgis10.5新功能图形缓冲
摘要 在输入要素周围某一指定距离内创建缓冲区多边形.在要素周围生成缓冲区时,大部分制图形状对缓冲区末端(端头)和拐角(连接)可用. 插图