UVa 481 - What Goes Up
题目大意:给你一系列数,找出它的最长(严格)递增子序列。
由于数据量较大,使用O(n2)的LIS算法会超时,要使用O(nlogn)的LIS算法,这里有详细的介绍。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef vector<int> vi; vi v, temp, pos, ans; int main()
{
#ifdef LOCAL
freopen("in", "r", stdin);
#endif
int x;
while (scanf("%d", &x) != EOF)
v.push_back(x);
temp.push_back(v[]);
pos.push_back();
for (int i = ; i < v.size(); i++)
{
x = v[i];
if (x > temp.back())
{
temp.push_back(x);
pos.push_back(temp.size());
}
else
{
vi::iterator it = lower_bound(temp.begin(), temp.end(), x);
*it = x;
pos.push_back(it-temp.begin()+);
}
}
for (int p = pos.size()-, len = temp.size(); p >= && len > ; p--)
if (pos[p] == len)
{
ans.push_back(v[p]);
len--;
}
cout << ans.size() << endl << '-' << endl;
for (int i = ans.size()-; i >= ; i--)
cout << ans[i] << endl;
return ;
}
UVa 481 - What Goes Up的更多相关文章
- What Goes Up UVA - 481 LIS+打印路径 【模板】
打印严格上升子序列: #include<iostream> #include<cstdio> #include<algorithm> #include<cst ...
- UVA 11021 - Tribles(概率)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=481&page=s ...
- uva 540 - Team Queue(插队队列)
首发:https://mp.csdn.net/mdeditor/80294426 例题5-6 团体队列(Team Queue,UVa540) 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队 ...
- UVA 540 Team Queue(模拟+队列)
题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...
- 1Z0-053 争议题目解析481
1Z0-053 争议题目解析481 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 481.Which statement is true about a running sessi ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
随机推荐
- R语言——基本绘图函数
通过一个综合的例子测试绘图函数 学习的内容是tigerfish老师的教程. 第一节:基本知识 用seq函数产生100位学生的学号. > num = seq(,) > num [] [] [ ...
- js 判断网页类型
<html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>标题页</title ...
- Nginx配置proxy_pass【转载】
在nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走. 下面四种 ...
- rstPixelType Constants
Constant Value Description PT_UNKNOWN -1 Pixel values are unknown. PT_U1 0 Pixel values are 1 bit. P ...
- android Spinner 续
android Spinner 续 动态增删Spinner中的数据项 public class EX04_09 extends Activity{ private static final Stri ...
- jdb 调试
C:\Users\Reverse>adb shell am start -D -n lwf.lc.pncdd/lwf.lc.pncdd.MainC 查看内存情况: cat /proc/N/map ...
- h2database. 官方文档
http://www.h2database.com/html/advanced.html http://www.h2database.com/html/tutorial.html#csv http:/ ...
- ubuntu中mysql修改编码utf8
摘要:Ubuntu Server 服务器下使用apt-get 命令安装的mysql,默认不是utf8.在这里记录一下如何将编码修改成utf8. 办法解决: 1.查看mysql编码 show varia ...
- CodeForces 621B Wet Shark and Bishops
记录一下每个对角线上有几个,然后就可以算了 #include<cstdio> #include<cstring> #include<cmath> #include& ...
- Nginx架构解析
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器. daemon守护线程 nginx在启动后 ...