题意:一个数组,一次操作为:除首尾不变,其它的=它与前后数字的中位数,这样对数组重复几次后数组会稳定不变。问要操作几次,及最后的稳定数组。

挺难的题,参考了别人的代码和思路。总的来说就是找01010,010101这样的,分别变为00000,000111。不知道谁发现的将它和异或联系起来。比如对010101异或前一个元素为011111(记为数组b),数组b中连续的1全置0,如果是奇数那么连续的1的中间置1.结果是000100(数组c)。再对数组c(除第一个元素)异或前一个元素,得到000111就是结果。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <ctime>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
int b[SZ]; int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//for(;scanf("%d",&n)!=EOF;)
{
int n;
cin>>n;
vector<int> vct;
for(int i=;i<n;++i)
{
int tmp;
cin>>tmp;
vct.push_back(tmp);
}
for(int i=;i<n;++i)
{
b[i]=vct[i]^vct[i-];
}
int res=;
for(int i=;i<n;)
{
int cur=;
int j=i;
for(;j<n;++j)
{
if(b[j]==)++cur;
else break;
}
res=max(res,(cur)/);
//cout<<"i: "<<i<<" "<<j<<endl;
for(int k=i;k<j;++k)
{
b[k]=;
}
if((j-i)&)
{
b[i+(j-i)/]=;
}
i=j+;
}
cout<<res<<endl;
int cur=vct[];
cout<<vct[];
for(int i=;i<n;++i)
{
//cout<<b[i]<<endl;
cout<<" ";
cout<<(cur^b[i]);
cur^=b[i];
}
cout<<endl;
}
return ;
}

codeforces590a//Median Smoothing//Codeforces Round #327 (Div. 1)的更多相关文章

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

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

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

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

  4. Codeforces Round #327 (Div. 2)

    题目传送门 水 A - Wizards' Duel 题目都没看清就写了,1e-4精度WA了一次... /************************************************ ...

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

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

  6. Codeforces Round #327 (Div. 2) C Median Smoothing(找规律)

    分析: 三个01组合只有八种情况: 000 s001 s010 0011 s100 s101 1110 s111 s 可以看出只有010,101是不稳定的.其他都是稳定的,且连续地出现了1或0,标记为 ...

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

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

  9. Codeforces Round #327 (Div. 2) D. Chip 'n Dale Rescue Rangers 二分 物理

    D. Chip 'n Dale Rescue Rangers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/co ...

随机推荐

  1. django基础 -- 2. django初识

    一.模块渲染  jinja2 实现简单的字符串替换(动态页面) 1.下载 pip install jinja2 示例 : html文件中 <!DOCTYPE html> <html ...

  2. Python 解析 XML 文件生成 HTML

    XML文件result.xml,内容如下: <ccm> <metric> <complexity>1</complexity> <unit> ...

  3. Python 打包中 setpy.py settuptools pbr 的了解

    背景 nova服务构建失败,报错: 'tests_require' must be a string or list of strings containing valid project/versi ...

  4. java 之 schema解析

    一,schema约束 *dtd语法:<ELEMENT 元素名 约束> *schema符合xml的语法,xml语句 **一个xml中可以有多个schema,多个schema使用名称空间区分( ...

  5. eclipse创建maven web项目工程步骤示例

    参考链接:https://www.cnblogs.com/noteless/p/5213075.html 需求表均同springmvc案例 此处只是使用maven 注意,以下所有需要建立在你的ecli ...

  6. 【译】第38节---EF6-基于代码的配置

    原文:http://www.entityframeworktutorial.net/entityframework6/code-based-configuration.aspx EF6引入了基于代码的 ...

  7. Linux学习之用户与root

    因为想要建立建立一个目录,但是发现权限不够,因为没用root登陆,所以学习了一下普通用户与root之间如何切换以及如何创建用户的一些知识. 1.pwd命令可以查看当前用户 $这个符号代表的就是普通用户 ...

  8. python学习 day15打卡 初识面向对象

    本节主要内容: 1.面向对象和面向过程 2.面向对象如何编写 3.面向对象和面向过程的对比 4.面向对象的三大特征 一.面向对象和面向过程(重点理解) 1.面向过程:一切以事物的流程为核心.核心是&q ...

  9. windows下远程连接Mysql

    使用“Ctrl + R”组合键快速打开cmd窗口,并输入“cmd”命令,打开cmd窗口. 使用“mysql -uroot -proot”命令可以连接到本地的mysql服务. 使用“use mysql” ...

  10. 1st,Python基础——01

    1 Python介绍 2 Python发展史 3 Python2 or 3? 4 Python安装 就不写了,各路大牛的博客都很详细. 5 Hello World程序 #!/usr/bin/env p ...