构造题。

答案可以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. C#常用集合的使用

    大多数集合都在System.Collections,System.Collections.Generic两个命名空间.其中System.Collections.Generic专门用于泛型集合. 针对特 ...

  2. 萝卜德森的sublime笔记中文翻译版

    我已经使用subliem编辑器版本2接近2个月了,并且我在其中找到了一堆有用的技巧.我发觉应该写下这些技巧,为那些对此感兴趣的人们.我会尽力的详细描述,那些看起来像魔法一样的东西,因为很多非常“酷”的 ...

  3. Tomcat服务器顶层结构和启动过程【转】

    号外:2016 最流行的是哪一种 Java 应用服务器呢? 通过从部署的 1240 个 JVM 中得到的数据,我们能够确定出现了 862 个容器供应商,或者说是占到了运行环境的 70% 左右.这些容器 ...

  4. window.open页面关闭后刷新父页面

    如题 function openWin(url,text,winInfo){ var winObj = window.open(url,text,winInfo); var loop = setInt ...

  5. 尚未配置为Web项目.指定的本地IIS URL http://localhsst/..要打开项目,需要配置虚拟目录 。是否立即创建虚拟目录 解决

    1.编辑.csproj文件 2.修改 UseIIS节点改为false,再次打开程序即可

  6. Unable to open connection to supplicant on "/data/misc/wifi/sockets/wlan0"

    在调试android wifi UI 的时候,出现了 logcat:  Unable to open connection to supplicant on "/data/misc/wifi ...

  7. 浅谈SQL Server 对于内存的管理

    简介 理解SQL Server对于内存的管理是对于SQL Server问题处理和性能调优的基本,本篇文章讲述SQL Server对于内存管理的内存原理. 二级存储(secondary storage) ...

  8. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  9. iOS 静态库,动态库与 Framework 浅析

    静态库与动态库的区别 首先来看什么是库,库(Library)说白了就是一段编译好的二进制代码,加上头文件就可以供别人使用. 什么时候我们会用到库呢?一种情况是某些代码需要给别人使用,但是我们不希望别人 ...

  10. PAT (Advanced Level) 1100. Mars Numbers (20)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...