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 ...
随机推荐
- centos 通过yum安装GlusterFS
1.环境 centos 6.5 64 bit glusterfs-3.5 2.配置yum源 http://download.gluster.org/pub/gluster/glusterfs/repo ...
- tp5分页注意,分页生成的ul class是pagination,有些模板可能将pagination定义为display:none
今天在调用分页时总是无法显示,查看网页源代码是正常的,后来发现是在css文件里将pagination定义为display:none,所以无法显示
- Exadata SL6 是个什么鬼?
就在 前两天,ORACLE的Exadata家族又发布了一个新成员:SL6. 变化上给人最直观的感觉是:从以前的X86架构变成了SPARC架构. Exadata Database Machine SL6 ...
- windows驱动环境配置vs2010+wdk7600
安装wdk后 要勾选集成VSIX选项到vs里面,不然vs里面新建项目时候找不到windows Driver 最简单的方式是安装wdk7600+vs2010+VisualDDK-1.5.7 这三个软件 ...
- Python网络爬虫(四)
关于Robots协议 Robots协议也称为爬虫协议,是网络爬虫排除标准(Robots Exclusion Protocol),用来告诉爬虫和搜索引擎哪些页面可以抓取,哪些不可以抓取.因为我们如果无限 ...
- python大战机器学习——模型评估、选择与验证
1.损失函数和风险函数 (1)损失函数:常见的有 0-1损失函数 绝对损失函数 平方损失函数 对数损失函数 (2)风险函数:损失函数的期望 经验风险:模型在数据集T上的平均损失 根据大 ...
- 【ACM】一种排序
一种排序 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都是整数 ...
- 009 Palindrome Number 判断一个正整数是否是回文数
详见:https://leetcode.com/problems/palindrome-number/description/ 实现语言:Java 方法一: class Solution { publ ...
- Unity Destroy和DestroyImmediate
Destroy(Object obj, float t = 0.0F); 删除一个游戏对象,组件或者资源. 物体obj现在被销毁或在指定了t时间过后销毁.如果obj是组件,它将从GameObject销 ...
- SpringBoot项目实现文件上传和邮件发送
前言 本篇文章主要介绍的是SpringBoot项目实现文件上传和邮件发送的功能. SpringBoot 文件上传 说明:如果想直接获取工程那么可以直接跳到底部,通过链接下载工程代码. 开发准备 环境要 ...