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

挺难的题,参考了别人的代码和思路。总的来说就是找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. Python3基础 list range+for 等差数列

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. 2870: 最长道路tree

    链接 https://www.lydsy.com/JudgeOnline/problem.php?id=2870 思路 先把树转化为二叉树 再链分治 %%yyb 代码 #include <ios ...

  3. Almost Union-Find (并查集+删除元素)题解

    思路: 当时只有暴力的思想,1.3都很好达到,只要加一个sum[ ]和num[ ]就可以,但是2比较麻烦,不知道谁以p为根,就想直接扫描然后一个个和p脱离关系,果然超时emmm.通常的想法是我们先用一 ...

  4. 使用closest替换parent

    尽量不要使用parent去获取DOM元素,如下代码: var $activeRows = $this.parent().parent().children(".active"); ...

  5. WijmoJS 使用Web Workers技术,让前端 PDF 导出效率更高效

    概述 Web Workers是一种Web标准技术,允许在后台线程中执行脚本处理. WijmoJS 的2018v3版本引入了Web Workers技术,以便在生成PDF时提高应用程序的运行速度. 一般来 ...

  6. Wijmo 2017路线图

    2016年是Wijmo团队发展和增长的另一个富有成效的一年.回顾我们2016年的路线图,您可以看到我们交付了我们承诺的一切.让我们回顾一下2016年的亮点: 我们第一个全面支持Angular 2 互操 ...

  7. Spring3.x 版本和 JDK1.8 不兼容导致 java.lang.IllegalStateException: Failed to load ApplicationContext

    由于安装了 JDK1.8 的版本,最近在进行整合 Struts2+Spring+Hibernate 框架的时候,不小心导入了之前下载的 Spring 3.2.0 版本的 jar 包. 结果在运行测试用 ...

  8. VirtualBox安装Centos6.8出现——E_INVALIDARG (0x80070057)

    VirtualBox使用已有的虚拟硬盘出错: 问题描述:UUID已经存在 Cannot register the hard disk 'E:\system_iso\centos6.8.vdi' {05 ...

  9. 【BZOJ】4011: [HNOI2015]落忆枫音

    题目链接:http://blog.csdn.net/popoqqq/article/details/45194103 写代码的时候也没有很清晰....具体看这里吧 #include<iostre ...

  10. codeforces 768D Jon and Orbs

    题目链接:http://codeforces.com/problemset/problem/768/D 令$f[i][j]$表示当前产生过了$i$个球,产生过了$j$个不同的球的概率. ${Ans_i ...