构造题。

答案可以o(n)构造出来。首先要发现规律。只有01交替的串才可能变化,变化规律如下:

1开头,长度为偶数(0结尾):变(len-2)/2次 变完后 前半1 后半0
1开头,长度为奇数(1结尾):变(len-1)/2次 变完后 全为1
0开头,长度为偶数(1结尾):变(len-2)/2次 变完后 前半0 后半1
0开头,长度为奇数(0结尾):变(len-1)/2次 变完后 全为0

然后就是在原串中寻找01交替串,然后按照上述规律进行变换。

#include <cstdio>
#include <cstring>
#include <vector>
#include<cmath>
#include<ctime>
#include<cstdlib>
using namespace std; const int maxn=;
int n;
int a[maxn],b[maxn]; struct X
{
int st,en;
int num;
}s[maxn];
int tot; int main()
{
while(~scanf("%d",&n))
{
for(int i=; i<=n; i++) scanf("%d",&a[i]);
a[]=a[]; a[n+]=a[n]; a[n+]=;
tot=; int pos=;
for(int i=pos;i<=n+;)
{
for(int j=i;j<=n+;j++)
{
if(a[j]==a[i]) continue;
else
{
if(j-!=i)
{
s[tot].st=i;
s[tot].en=j-;
s[tot].num=a[i];
tot++;
}
i=j;
break;
}
}
} int ans=;
for(int i=;i<=n;i++) b[i]=a[i]; for(int i=;i<tot+;i++)
{
int len=s[i+].st-s[i].en+;
if(s[i].num==)
{
if(s[i+].num==)
{
ans=max(ans,(len-)/);
for(int k=s[i].en;k<=s[i].en+len/-;k++) b[k]=;
for(int k=s[i].en+len/;k<=s[i+].st;k++) b[k]=;
}
else
{
ans=max(ans,(len-)/);
for(int k=s[i].en;k<=s[i].en+len/-;k++) b[k]=;
for(int k=s[i].en+len/;k<=s[i+].st;k++) b[k]=;
}
}
else
{
if(s[i+].num==)
{
ans=max(ans,(len-)/);
for(int k=s[i].en;k<=s[i].en+len/-;k++) b[k]=;
for(int k=s[i].en+len/;k<=s[i+].st;k++) b[k]=;
}
else
{
ans=max(ans,(len-)/);
for(int k=s[i].en;k<=s[i].en+len/-;k++) b[k]=;
for(int k=s[i].en+len/;k<=s[i+].st;k++) b[k]=;
}
}
} printf("%d\n",ans);
for(int i=; i<=n; i++) printf("%d ",b[i]);
printf("\n");
}
return ;
}

CodeForces 590A Median Smoothing的更多相关文章

  1. ACM学习历程—CodeForces 590A Median Smoothing(分类讨论 && 数学)

    题目链接:http://codeforces.com/problemset/problem/590/A 题目大意是给一个串,头和尾每次变换保持不变. 中间的a[i]变成a[i-1],a[i],a[i+ ...

  2. codeforces 590A A. Median Smoothing(思维)

    题目链接: A. Median Smoothing time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  3. 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 ...

  4. 【22.70%】【codeforces 591C】 Median Smoothing

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 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 ...

  6. Codeforces Round #327 (Div. 2)C. Median Smoothing 构造

    C. Median Smoothing   A schoolboy named Vasya loves reading books on programming and mathematics. He ...

  7. Codeforces 590 A:Median Smoothing

    A. Median Smoothing time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. cf590A Median Smoothing

    A. Median Smoothing time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing

    http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...

随机推荐

  1. Apache开启gzip压缩传输

    修改Apache配置文件 第一步,添加两个模块 LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module m ...

  2. 点击按钮颜色变深.通过ColorFilter ColorMatrix

    private ImageButton imgeBtn; // 颜色矩阵 public final float[] BT_SELECTED = new float[] { 1, 0, 0, 0, -5 ...

  3. MyBatis-xml配置SQL文件中,传入List数组、基本类型String、int……、与自定义类型的方法

    //基本类型 @Override public String queryItemNumber(String packId) throws Exception { // TODO Auto-genera ...

  4. servlet多次跳转报IllegalStateException异常

    当发生在如下错误的时候,有一个方案可行, "java.lang.IllegalStateException: Cannot forward after response has been c ...

  5. OpenGL---------BMP文件格式

    计算机保存图象的方法通常有两种:一是“矢量图”,一是“像素图”.矢量图保存了图象中每一几何物体的位置.形状.大小等信息,在显示图象时,根据这些信息计算得到完整的图象.“像素图”是将完整的图象纵横分为若 ...

  6. spark中groupByKey与reducByKey

    [译]避免使用GroupByKey Scala Spark 技术   by:leotse 原文:Avoid GroupByKey 译文 让我们来看两个wordcount的例子,一个使用了reduceB ...

  7. Eclipse最有用的快捷键

    编辑 Ctrl+1 快速修复(最经典的快捷键,就不用多说了,可以解决很多问题,比如import类.try catch包围等) Ctrl+Shift+F 格式化当前代码 Ctrl+Shift+M 添加类 ...

  8. 自定义solr的search UI

    solr使用apache的velocity来定义UI,在solr的search ui的基础上更改即可,主要改\example\solr\collection1\conf\velocity里的文件. 详 ...

  9. js的阻塞特性

    JS具有阻塞特性,当浏览器在执行js代码时,不能同时做其它事情,即<script>每次出现都会让页面等待脚本的解析和执行(不论JS是内嵌的还是外链的),JS代码执行完成后,才继续渲染页面. ...

  10. java几种常用设计模式简单示例

    1.单例设计模式 所谓单例设计模式简单说就是无论程序如何运行,采用单例设计模式的类(Singleton类)永远只会有一个实例化对象产生.具体实现步骤如下: (1) 将采用单例设计模式的类的构造方法私有 ...