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的更多相关文章

  1. I - Beautiful People ZOJ - 2319 (二分法)

    The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...

  2. 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 ...

  3. zoj 2829 Beautiful Number

    Beautiful Number Time Limit: 2 Seconds      Memory Limit: 65536 KB Mike is very lucky, as he has two ...

  4. zoj 2850 Beautiful Meadow

    Beautiful Meadow Time Limit: 2 Seconds      Memory Limit: 65536 KB Tom's Meadow Tom has a meadow in ...

  5. ZOJ 2319 Beatuiful People(单调递增序列的变形)

    Beautiful People Time Limit: 5 Seconds      Memory Limit: 32768 KB      Special Judge The most prest ...

  6. ZOJ 3213 Beautiful Meadow 简单路径 插头DP

    简单路径的题目,其实就是在状态后面多记了有多少个独立插头. 分类讨论独立插头: 1.只存在上插头或者左插头,可以选择作为独立插头. 2.都不存在上插头和左插头,选择作为独立插头的同时要标号为新的连通块 ...

  7. ASC #1

    开始套题训练,第一套ASC题目,记住不放过每一题,多独立思考. Problem A ZOJ 2313 Chinese Girls' Amusement 循环节 题意:给定n,为圆环长度,求k < ...

  8. 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 ...

  9. ZOJ 2850和ZOJ 1414

    下午上数据结构,结果竟然没有新题.T T果断上OJ来水一发 ZOJ 2850   Beautiful Meadow 传送门http://acm.zju.edu.cn/onlinejudge/showP ...

随机推荐

  1. CD0J/POJ 851/3126 方老师与素数/Prime Path BFS

    Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9982   Accepted: 5724 Descri ...

  2. vue 组件开发 props 验证

    使用props 在Vue中父组件向子组件中传送数据是通过props实现的,一个简单的使用props的例子: <!DOCTYPE html> <html> <head> ...

  3. MVC基类控制器的会话丢失重新登录权限过滤

    SSOController.cs请查看以下代码: public class SSOController : Controller { public const string Token = " ...

  4. Redis在Windows+linux平台下的安装配置(转)

    window平台Redis安装 下载地址: http://code.google.com/p/servicestack/wiki/RedisWindowsDownload Redis文件夹有以下几个文 ...

  5. JavaScript 新手的踩坑日记

    引语 在1995年5月,Eich 大神在10天内就写出了第一个脚本语言的版本,JavaScript 的第一个代号是 Mocha,Marc Andreesen 起的这个名字.由于商标问题以及很多产品已经 ...

  6. MVC二级联动使用$.ajax方法获取后端返回的字符串

    在"MVC二级联动使用$.getJSON方法"中使用$.getJSON()获取后端返回的JSon. 本篇使用jQuery的$.ajax()获取后端返回的字符串,实现二级联动.   ...

  7. C#编程(三)

    原文链接:http://blog.csdn.net/shanyongxu/article/details/46398713 C#中的常量 定义常量所需要的关键字:const,语法结果:const 变量 ...

  8. Android调用手机中的应用市场,去评分的功能实现

    在我们常常使用的软件当中,我们经常可以看到在软件的设置界面,有一个功能那就是去评分的功能,只要我们一点击“去评分”就会调用手机中的应用市场软件.一开始我以为这个功能的实现是要遍历整个手机中的软件包名, ...

  9. java中初始化对象变量的方法

    1.在类定义对象的地方初始化 2.在类构造器中初始化 3.在正要使用这些对象之前,惰性初始化,或者叫惰性载入 4.使用实例初始化    在方法里使用初始化

  10. 理解与学习linux 文件系统的目录结构

    1. linux文件系统的结构 linux文件系统是以一种树形结构存在,Linux的文件系统的入口就是/,所有的目录.文件.设备都在/之下,/就是Linux文件系统的组织者,也是最上级的领导者. 2. ...