Codeforces Round #327 (Div. 2) C Median Smoothing(找规律)
分析:
三个01组合只有八种情况:
000 s
001 s
010 0
011 s
100 s
101 1
110 s
111 s
可以看出只有010,101是不稳定的。其他都是稳定的,且连续地出现了1或0,标记为s。
考虑连续的不稳定串的,例子:
11010100
s s
110100
s s
1100
只有两种情况,两个边界是不同(11和00)或者相同(11或者00)。
前者中间的不稳定串的长度是2*k,且经过k次将变成11110000,而后者的不稳定串的长度是2*k+1,中间经过k+1将变得和两边一样。
变化次数取所有情况的最大值。
熄灯了~碎觉 QAQ ~
(做这种题的科学方法就是,打打表,写程序枚举枚举样例就有思路了。(人工枚举可能会选择性漏掉某些情况
#include<bits/stdc++.h>
using namespace std; typedef long long ll; const int maxn = 5e5;
int x[maxn]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n; scanf("%d",&n);
for(int i = ; i < n; i++){
scanf("%d", x+i);
}
int ans = ;
for(int i = ; i < n-; i++){
if(x[i] != x[i-]){
int j = i;
while(j<n- && x[j] != x[j+] && x[j] != x[j-]) j++;
ans = max(ans, (j-i+)>>);
int p = i, q = j-;
while(p<=q){
x[p++] = x[i-];
x[q--] = x[j];
}
i = j;
}
}
printf("%d\n", ans);
for(int i = ; i < n; i++){
printf("%d%c", x[i], i == n-? '\n': ' ');
}
return ;
}
Codeforces Round #327 (Div. 2) C Median Smoothing(找规律)的更多相关文章
- Codeforces Round #327 (Div. 2) C. Median Smoothing 找规律
C. Median Smoothing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/p ...
- Codeforces Round #327 (Div. 2)C. Median Smoothing 构造
C. Median Smoothing A schoolboy named Vasya loves reading books on programming and mathematics. He ...
- Codeforces Round #347 (Div. 2) C. International Olympiad 找规律
题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...
- Codeforces Round #327 (Div. 2) B. Rebranding C. Median Smoothing
B. Rebranding The name of one small but proud corporation consists of n lowercase English letters. T ...
- Codeforces Round #327 (Div. 2)
题目传送门 水 A - Wizards' Duel 题目都没看清就写了,1e-4精度WA了一次... /************************************************ ...
- Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing
http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...
- codeforces590a//Median Smoothing//Codeforces Round #327 (Div. 1)
题意:一个数组,一次操作为:除首尾不变,其它的=它与前后数字的中位数,这样对数组重复几次后数组会稳定不变.问要操作几次,及最后的稳定数组. 挺难的题,参考了别人的代码和思路.总的来说就是找01010, ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #327 (Div. 2) E. Three States BFS
E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...
随机推荐
- Codeforces Round #507 (Div. 2)C(贪心,逆向遍历,构造)
#include<bits/stdc++.h>using namespace std;int order[300007];long long t[300007],ans[300007];i ...
- angular学习笔记【ng2-charts】插件添加
原文:https://segmentfault.com/a/1190000008077830 1. 安装 ng2-charts npm install ng2-charts --save2. 还必须引 ...
- django 请求生命周期
详细例子:
- 基于Jquery的文本提示控件 poshytip
Html中,如设置了title的属性,则当鼠标在该对象上面短暂的停留时,会显示预设的文本提示,但,这些效果只会短暂的显示,一会就会消失,又要重新把鼠标移出再移回来才被显示,样式也无法重写,实在是恼人之 ...
- spring boot test MockBean
使用spring boot , MockBean @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) p ...
- 练习四十六:列表排序,删除list中重复的元素
方法一:使用集合set;将list直接转换为set a = [1,3,4,3,5,7] a = list(set(a)) print(a) 执行结果: [1, 3, 4, 5, 7] 方法二:直接排序 ...
- java——helloword
第一次接触Java,感觉乱乱的,需要捋清楚一些概念再安装java. 首先,什么是JDK,什么是JRE呢? JRE:JAVA运行环境(Java Runtime Envirnment) JDK:Java开 ...
- Spring 学习(三)AOP
(1)AOP概述 - AOP:面向切面编程,扩展功能不修改源代码实现 - AOP采取横向抽取机制,取代了传统的纵向继承体系重复性代码 (2)AOP底层原理 原始方法------->纵向继承体系 ...
- 湖南省第十二届大学生计算机程序设计竞赛 problem A 2016
如果 a * b % 2016 == 0 如果a = 1 ,且 a * b % 2016 == 0 考虑一下a = 2017的时候 2017 * b = (2016 + 1) * b % 2016 = ...
- Python 的execfile用法
可以直接执行脚本 而import是将脚本导入另一个文件里,可以看 http://docs.python.org/2/library/functions.html 例如一个Python文件 a.py: ...