ZOJ 2319 Beautiful People
来源:互联网 发布:js公历转农历 编辑:程序博客网 时间:2024/04/28 08:33
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_pairusing 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
- ZOJ 2319 Beautiful People
- zoj 2319 Beautiful People
- Beautiful People (zoj 2319)
- Beautiful People - ZOJ 2319 dp
- zoj 2319 Beautiful People 【最长上升序列】
- 【LIS变形】 zoj 2319 Beautiful People
- zoj 3519 Beautiful People
- Beautiful People ZOJ
- Beautiful People ZOJ
- Beautiful People ZOJ
- ZOJ Problem Set - 2319 Beautiful People || sgu 199
- ZOJ 2319 Beautiful People(LIS二分法+路径输出)
- ZOJ 2319 Beautiful People (LIS的变形)
- ZOJ 2319 Beautiful People(最长单调递增子序列)(二维LIS)
- Beautiful People
- ZOJ 2319 Beatuiful People
- zoj 2391 Beautiful People 最长上升子序列
- 解决html换行出现空格问题
- ListView
- C# word类库 光标移动
- php.ini 中开启短标签 <?=$?>
- BCB TOpenDialog组件的典型用法
- ZOJ 2319 Beautiful People
- 15个极好的Linux find命令示例
- Mongo 初涉
- 第十周上机实践项目二
- nutch with solr getting started
- php实现ios推送
- 求1/2-2/3+3/4.....+19/20的值
- AutoCompleteTextView
- ArrayList与LinkedList迭代时间比较