SGU 488 Dales and Hills
这给题目和LIS类似,只不过是求连续的单调序列,用单调队列可破之,比如求LDIS(连续单增序列),如果a[i]大于栈顶元素入栈,将top作为序列长度,反过来再扫一遍就是包含该元素的单调递减序列,这样通过LCDS,LCIS函数可得到4个存储某元素左右的单调增,减的数组。然后枚举一遍就可以。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 1111111
#define INF 0x0f0f0f0f
using namespace std; int stack1[N];//不要在函数里开大数组!!!
int n;
void LCIS(int dp[],int a[])
{
int top=;
stack1[top]=-INF;
for(int i=;i<=n;i++)
{
if(a[i]>stack1[top])
{
stack1[++top]=a[i];
dp[i]=top;
}
else top=,stack1[]=a[i],dp[i]=top;
}
}
void LDIS(int dp[],int a[])
{
int top=;
stack1[top]=INF;
for(int i=;i<=n;i++)
if(a[i]<stack1[top])
{
stack1[++top]=a[i];
dp[i]=top;
}
else top=,stack1[top]=a[i],dp[i]=top;
} int dp1[N],dp2[N],dp3[N],dp4[N];
int a[N],b[N]; int main(void)
{
int tc;
scanf("%d",&tc);
while(tc--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",a+i),b[n+-i]=a[i];
LCIS(dp1,a);
LCIS(dp2,b);
LDIS(dp3,a);
LDIS(dp4,b);
int ans1=,ans2=;
for(int i=;i<=n;i++)
{
ans1=max(ans1,min(dp1[i]-,dp2[n+-i]-));
ans2=max(ans2,min(dp3[i]-,dp4[n+-i]-));
}
printf("%d %d\n",ans1,ans2);
}
return ;
}
SGU 488 Dales and Hills的更多相关文章
- 2009-2010 ACM-ICPC, NEERC, Western Subregional Contest
2009-2010 ACM-ICPC, NEERC, Western Subregional Contest 排名 A B C D E F G H I J K L X 1 0 1 1 1 0 1 X ...
- SGU 495. Kids and Prizes
水概率....SGU里难得的水题.... 495. Kids and Prizes Time limit per test: 0.5 second(s)Memory limit: 262144 kil ...
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU】495. Kids and Prizes
http://acm.sgu.ru/problem.php?contest=0&problem=495 题意:N个箱子M个人,初始N个箱子都有一个礼物,M个人依次等概率取一个箱子,如果有礼物则 ...
- SGU 455 Sequence analysis(Cycle detection,floyd判圈算法)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=455 Due to the slow 'mod' and 'div' operati ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
- 树形DP求树的重心 --SGU 134
令一个点的属性值为:去除这个点以及与这个点相连的所有边后得到的连通分量的节点数的最大值. 则树的重心定义为:一个点,这个点的属性值在所有点中是最小的. SGU 134 即要找出所有的重心,并且找出重心 ...
- SGU 170 Particles(规律题)
题目链接:http://acm.sgu.ru/problem.php?contest=0&problem=170 解题报告:输入两个由'+'和'-'组成的字符串,让你判断第二个串能不能由第一个 ...
随机推荐
- 【转】java.util.vector中的vector的详细用法
[转]java.util.vector中的vector的详细用法 ArrayList会比Vector快,他是非同步的,如果设计涉及到多线程,还是用Vector比较好一些 import java.uti ...
- JAXB - XML Schema Types, Defining Subtypes
Although object orientation isn't a key feature of XML or the XML Schema language, it's still possib ...
- Android线控的使用
实现方式一:只能在程序为前台时监控 在Activity中即可监听 @Override public boolean onKeyUp(int keyCode, KeyEvent event) { Log ...
- Centos7最小化安装后(minimal)安装图形界面
centos7下载地址:http://mirrors.cqu.edu.cn/CentOS/7/isos/x86_64/CentOS-7-x86_64-Minimal-1511.iso 下载后用vmwa ...
- QT宏 Q_OBJECT,explicit, QHostAddress, quint, emit
QT相關 一. 參考: 1.宏Q_OBJECT 二. explicit struct constrcution 三. QHostAddress Detailed Description: The QH ...
- 九度OJ 1499 项目安排 -- 动态规划
题目地址:http://ac.jobdu.com/problem.php?pid=1499 题目描述: 小明每天都在开源社区上做项目,假设每天他都有很多项目可以选,其中每个项目都有一个开始时间和截止时 ...
- ajax、json一些整理(2)
<script type="text/javascript"> $(document).ready(function(){ $("#btn").cl ...
- 使用weinre通过PC浏览器调试手机网页
Weinre是什么? Weinre代表Web Inspector Remote,是一种远程调试工具.举个例子,在电脑上可以即时的更改手机上对应网页的页面元素.样式表, 或是查看Javascript变量 ...
- 最完美解决Nginx部署ThinkPHP项目的办法
网上通用解决方法的配置如下: server { ... location / { index index.htm index.html index.php; #访问路径的文件不存在则重写URL转交给T ...
- c++二分答案 之 跳石头
题目: 题目描述 Description 一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之 ...