Codeforces Round #FF (Div. 2) C. DZY Loves Sequences
解题报告:输入一个数列,选取一个子数列,要求最多只能改动这个子数列中的一个数,使得这个子数列是严格的升序的(严格升序没有相等的)
我的做法是,第一步把这个 数列的每个升序的子数列都找出来,然后看这些子数列能不能和跟它相邻的升序的子数列连接起来。
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = +;
typedef __int64 INT;
INT que[maxn];
struct node
{
int f,r,l;
}da[maxn]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i = ;i < n;++i)
scanf("%I64d",&que[i]);
INT f = ,temp = que[],s = ;
que[n] = -0x7ffffffff;
for(int i = ;i < n;++i)
if(que[i] >= que[i + ])
{
da[f].f = s;
da[f].r = i;
da[f].l = da[f].r - da[f].f + ;
s = i+;
f++;
}
// for(int i = 0;i < f;++i)
// printf("%d %d %d\n",da[i].f,da[i].r,da[i].l);
int ans = ;
for(int i = ;i < f - ;++i)
{
ans = max(ans,da[i].l);
if(f > )
ans = max(ans,da[i].l + );
if(da[i].l > && que[da[i].r - ] < que[da[i+].f] - )
ans = max(ans,da[i].l + da[i+].l);
if(da[i+].l > && que[da[i].r] < que[da[i+].f + ] - )
ans = max(ans,da[i].l + da[i+].l);
}
if(f == )
ans = da[].l;
if(f > )
ans = max(ans,da[f-].l+);
printf("%d\n",ans);
}
return ;
}
Codeforces Round #FF (Div. 2) C. DZY Loves Sequences的更多相关文章
- DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences 动态规划
A. DZY Loves Sequences 题目连接: http://www.codeforces.com/contest/446/problem/A Description DZY has a s ...
- Codeforces Round #FF (Div. 1) A. DZY Loves Sequences
题目链接: http://www.codeforces.com/contest/446/problem/A 题解: dp1[x]表示以x结尾的最大严格升序连续串,dp2[x]表示以x开头的最大严格升序 ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification 优先队列
B. DZY Loves Modification 题目连接: http://www.codeforces.com/contest/446/problem/B Description As we kn ...
- Codeforces Round #FF (Div. 2) D. DZY Loves Modification 优先队列
D. DZY Loves Modification time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #FF (Div. 1) B. DZY Loves Modification
枚举行取了多少次,如行取了i次,列就取了k-i次,假设行列单独贪心考虑然后相加,那么有i*(k-i)个交点是多出来的:dpr[i]+dpc[k-i]-i*(k-i)*p 枚举i取最大值.... B. ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树
http://codeforces.com/contest/447/problem/E 题意: 给定一个数组, m次操作, 1 l r 表示区间修改, 每次 a[i] + Fibonacci[i-l ...
- Codeforces Round #FF (Div. 2) A. DZY Loves Hash
DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the ...
随机推荐
- 云计算之路-阿里云上:遭遇CDN问题
7月10日11:14接到一位用户反馈,访问园子时加载不了 common.cnblogs.com/script/jquery.js 这个文件. 由于这个域名用了阿里云CDN,所以我们判断可能是某个CDN ...
- deerlet-redis-client添加集群支持,邀请各路大神和菜鸟加入。
引言 经过几周的修改,deerlet已经添加了对于redis集群的支持,策略与memcached客户端一样,采用一致性Hash.不过目前Hash的算法取自Java自带的String类型的HashCod ...
- 机器学习中的矩阵方法03:QR 分解
1. QR 分解的形式 QR 分解是把矩阵分解成一个正交矩阵与一个上三角矩阵的积.QR 分解经常用来解线性最小二乘法问题.QR 分解也是特定特征值算法即QR算法的基础.用图可以将分解形象地表示成: 其 ...
- c#简单自定义异常处理日志辅助类
简单写了一个错误日志记录辅助类,记录在此. Loghelper类 using System; using System.Collections.Generic; using System.IO; us ...
- Linq之Expression高级篇(常用表达式类型)
目录 写在前面 系列文章 变量表达式 常量表达式 条件表达式 赋值表达式 二元运算符表达式 一元运算符表达式 循环表达式 块表达式 总结 写在前面 首先回顾一下上篇文章的内容,上篇文章介绍了表达式树的 ...
- 每天一个linux命令(26):du 命令
Linux du命令也是查看使用空间的,但是与df命令不同的是Linux du命令是对文件和目录磁盘使用的空间的查看,还是和df命令有一些区别的. 1.命令格式: du [选项][文件] 2.命令功能 ...
- java.lang.NoClassDefFoundError: org/objectweb/asm/Type
Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/ ...
- Linux 进程管理器 supervixor
使用 supervisor 管理进程 http://www.cnblogs.com/smail-bao/p/5673434.html http://ju.outofmemory.cn/entry/20 ...
- 负margin一些奇葩的布局技巧
copy_from_ http://www.hicss.net/i-know-you-do-not-know-the-negative-margin/ <!doctype html> &l ...
- 【Gym 100971J】Robots at Warehouse
题意 链接给你一个n*m的地图,'#'代表墙,‘.’代表可走的,1代表1号机器人,2代表2号机器人,机器人可以上下左右移动到非墙的位置,但不能走到另一个机器人身上.问能否交换1和2的位置. 分析 如果 ...