构造题。

答案可以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. Linux常用Shell脚本珍藏【转载】

    我们在运维中,尤其是linux运维,都知道脚本的重要性,脚本会让我们的 运维事半功倍,所以学会写脚本是我们每个linux运维必须学会的一门功课,这里收藏linux运维常用的脚本.如何学好脚本,最关键的 ...

  2. MySQL启动相关知识

    使用mysqld和mysqld_safe启动的区别 直接运行mysqld程序来启动MySQL服务的方法很少见,mysqld_safe脚本[注意:mysqld_safe只是一个脚本]会在启动MySQL服 ...

  3. codeforces DIV2 D 最短路

    http://codeforces.com/contest/716/problem/D 题目大意:给你一些边,有权值,权值为0的表示目前该边不存在,但是可以把0修改成另外一个权值.现在,我们重新建路, ...

  4. Eclipse+EPIC+PadWalker

    来源: http://www.cnblogs.com/itech/archive/2010/02/23/1671676.html http://blog.csdn.net/haoyujie/artic ...

  5. JSP导出Excel后身份证后三位为0

    JSP导出Excel身份证号码超出Excel最大限制,用科学计数法表示,但后三位为0,修改方式: <style type="text/css">.txt    {    ...

  6. shell中 if else以及大于、小于、等于逻辑表达式介绍

    比如比较字符串.判断文件是否存在及是否可读等,通常用"[]"来表示条件测试. 注意:这里的空格很重要.要确保方括号的空格.笔者就曾因为空格缺少或位置不对,而浪费好多宝贵的时间. i ...

  7. 分页打印控制 摘自于网络:http://www.cnblogs.com/joinger/articles/1807517.html

    代码 style="page-break-after:always;"> 利用CSS控制打印 放在这里,算是一个备份 <style> @media print{ ...

  8. 简单粗暴的“Debug模式”

    在项目中,通常会遇到:调试程序和程序在线上运行时程序运行的参数不一样, 例如线上运行时程序是获取线上的机器的ip,而调试程序时,我们会指定一个ip进行调试. 又或者项目要与多个系统进行数据交换,调试的 ...

  9. Linux系统查看有几块硬盘

    使用df命令即可查看.df 是来自于coreutils 软件包,系统安装时,就自带的:我们通过这个命令可以查看磁盘的使用情况以及文件系统被挂载的位置: 示例:[root@localhost ~]# d ...

  10. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...