构造题。

答案可以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. [code]最长回文子串

    分析: 不能用scanf("%s"),因为碰到空格或者Tab就会停下来. 解决输入中有空格 方法一:使用fgetc(fin),读取一个打开的文件fin,读取一个字符,然后返回一个i ...

  2. table新增空白行到首行

    var str=""; str+="<tr bordercolor='#DEDEDE' bgcolor='#ffffff'>"; str+=&quo ...

  3. on-tap和on-click

    简单的说,当你点击移动设备屏幕上的一个点之后,on-tap会立刻触发,而on-click(可能)需要等待300ms才触发——这是移动设备浏览器为了检测是否存在双击的一个检测周期长度. 在移动设备上,应 ...

  4. __declspec(dllexport) 和 __declspec(dllimport)的作用

    operatordll.h #include <iostream> #ifndef _WIN32 #define DLL_EXPORT#else #ifdef OPERATORDLL_EX ...

  5. iOS 10推送通知开发

    原文地址:Developing Push Notifications for iOS 10,译者:李剑飞 虽然通知经常被过度使用,但是通知确实是一种获得用户关注和通知他们需要更新或行动的有效方式.iO ...

  6. sql server中单引号拼接字符串(书写错误会出现错误"浮点值 XXXX 超出了计算机表示范围(8 个字节)。“XX”附近有语法错误。")

    " ' "(单引号)的运用:在sql server中,两个" ' "(单引号)在拼接字符串的情况下运用,就是表示拼接上了一个" ' "单引号 ...

  7. C# Socket的TCP通讯

    Socket的TCP通讯 一. socket的通讯原理 服务器端的步骤如下. (1)建立服务器端的Socket,开始侦听整个网络中的连接请求. (2)当检测到来自客户端的连接请求时,向客户端发送收到连 ...

  8. OPenGL中的缓冲区对象

    引自:http://blog.csdn.net/mzyang272/article/details/7655464 在许多OpenGL操作中,我们都向OpenGL发送一大块数据,例如向它传递需要处理的 ...

  9. Python定制类

    https://docs.python.org/3/reference/datamodel.html#special-method-names

  10. Java NIO Related

    A file's status is 3-valued: The file is verified to exist; The file is verified to not exist; The f ...