【Codeforces 446A】DZY Loves Sequences
【链接】 我是链接,点我呀:)
【题意】
让你找一段连续的区间
使得这一段区间最多修改一个数字就能变成严格上升的区间。
问你这个区间的最长长度
【题解】
dp[0][i]表示以i为结尾的最长严格上升长度
dp[1][i]表示以i作为开头的最长严格上升长度.
然后我们枚举那个改变的位置在什么地方就可以了。
别忘了不改变的那种情况。
可以一起做。
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)1e5;
static class Task{
public void solve(InputReader in,PrintWriter out) {
int n;
int []a = new int [N+10];
int [][]f =new int[2][N+10];
n = in.nextInt();
for (int i = 1;i <= n;i++) a[i] = in.nextInt();
for (int i = 1;i <= n;i++) {
f[0][i] = 1;
if (i-1>=1 && a[i]>a[i-1]) {
f[0][i] = f[0][i-1] + 1;
}
}
for (int i = n;i >= 1;i--) {
f[1][i] = 1;
if (i+1<=n && a[i]<a[i+1])
f[1][i] = f[1][i+1]+1;
}
int MI = -(int)1e9-1,MA = (int)1e9 + 1;
int ans = 0;
for (int i = 1;i <= n;i++) {
int x,y;
x = MI;y = MA;
if (i-1>=1) x = a[i-1];
if (i+1<=n) y = a[i+1];
if (y>x+1) {
ans = Math.max(ans, f[0][i-1]+f[1][i+1]+1);
}else {
ans = Math.max(ans, Math.max(f[0][i-1]+1, f[1][i+1]+1));
}
ans = Math.max(ans, f[0][i]);
ans = Math.max(ans, f[1][i]);
}
out.println(ans);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 446A】DZY Loves Sequences的更多相关文章
- 【Codeforces 444A】DZY Loves Physics
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 两个点的子图他们的"密度"是比所有联通生成子图都要大的 "只要胆子大,遇到什么问题都不怕!" [代码] ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- 【BZOJ3563/BZOJ3569】DZY Loves Chinese I/II(随机化,线性基)
[BZOJ3563/BZOJ3569]DZY Loves Chinese I/II(随机化,线性基) 题面 搞笑版本 正经版本 题面请自行观赏 注意细节. 题解 搞笑版本真的是用来搞笑的 所以我们来讲 ...
- 【BZOJ3563/3569】DZY Loves Chinese II 线性基神题
[BZOJ3563/3569]DZY Loves Chinese II Description 神校XJ之学霸兮,Dzy皇考曰JC. 摄提贞于孟陬兮,惟庚寅Dzy以降. 纷Dzy既有此内美兮,又重之以 ...
- UOJ_14_【UER #1】DZY Loves Graph_并查集
UOJ_14_[UER #1]DZY Loves Graph_并查集 题面:http://uoj.ac/problem/14 考虑只有前两个操作怎么做. 每次删除一定是从后往前删,并且被删的边如果不是 ...
- [CodeForces - 447C] C - DZY Loves Sequences
C - DZY Loves Sequences DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai ...
- 【bzoj 3309 】 DZY Loves Math
Description 对于正整数n,定义f(n)为n所含质因子的最大幂指数.例如f(1960)=f(2^3 * 5^1 * 7^2)=3, f(10007)=1, f(1)=0.给定正整数a,b,求 ...
- Codeforces 447 C DZY Loves Sequences【DP】
题意:给出一列数,在这个序列里面找到一个连续的严格上升的子串,现在可以任意修改序列里面的一个数,问得到的子串最长是多少 看的题解,自己没有想出来 假设修改的是a[i],那么有三种情况, 1.a[i]& ...
- 【Codeforces 1114C】Trailing Loves (or L'oeufs?)
[链接] 我是链接,点我呀:) [题意] 问你n!的b进制下末尾的0的个数 [题解] 证明:https://blog.csdn.net/qq_40679299/article/details/8116 ...
随机推荐
- mst
https://www.zybuluo.com/ysner/note/1245941 题面 给一个\(n\)点完全图,点权均小于\(2^m\).定义边权等于两端点点权的与和(即\(a_i\&b ...
- hash练习们
610. 数对的个数 ★★ 输入文件:dec.in 输出文件:dec.out 简单对比时间限制:1 s 内存限制:128 MB Description出题是一件痛苦的事情!题目看多了也 ...
- sql 查询出当天记录数据
select updatetime,NewComment,HistoryID,sum(1) over(partition by UpdateTime) from LPProjectHistoryord ...
- js 获取URL的值
今天碰到要在一个页面获取另外一个页面url传过来的参数,一开始很本能的想到了用 split("?")这样一步步的分解出需要的参数. 后来想了一下,肯定会有更加简单的方法的!所以在网 ...
- NS2学习笔记(二)
Tcl语言 变量和变量赋值 set a "Hello World!" #将字符串赋值给变量a puts "NS2 say $a" #输出字符串的内容,其中$a表 ...
- JavaScript--输出内容(document.write)
document.write() 可用于直接向 HTML 输出流写内容.简单的说就是直接在网页中输出内容. 第一种:输出内容用“”括起,直接输出""号内的内容. <scrip ...
- HTML--文本输入框、密码输入框
当用户要在表单中键入字母.数字等内容时,就会用到文本输入框.文本框也可以转化为密码输入框. 语法: <form> <input type="text/password&qu ...
- Codeforces 792C
题意:给出一个由0到9数字构成的字符串,要求删去最少的数位,使得这个字符串代表的数能被3整除,同时要求不能有前导零,并且至少有一位(比如数字11,删去两个1后就没有数位了,所以不符合).如果能够处理出 ...
- C#内容格式刷html 转成txt
/// <summary> /// 内容格式刷 /// </summary> /// <param name="strHtml">要格式的文本& ...
- Linq学习(二)-本次学习用到的资料
本次学习用到的数据库初始化脚本如下 use KMS create table Blog_User ( UserId ,1), NickName ), CreateTime datetime ) cre ...