codeforces590a//Median Smoothing//Codeforces Round #327 (Div. 1)
题意:一个数组,一次操作为:除首尾不变,其它的=它与前后数字的中位数,这样对数组重复几次后数组会稳定不变。问要操作几次,及最后的稳定数组。
挺难的题,参考了别人的代码和思路。总的来说就是找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)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #327 (Div. 2)C. Median Smoothing 构造
C. Median Smoothing A schoolboy named Vasya loves reading books on programming and mathematics. He ...
- Codeforces Round #327 (Div. 2)
题目传送门 水 A - Wizards' Duel 题目都没看清就写了,1e-4精度WA了一次... /************************************************ ...
- Codeforces Round #327 (Div. 1), problem: (A) Median Smoothing
http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开 ...
- Codeforces Round #327 (Div. 2) C Median Smoothing(找规律)
分析: 三个01组合只有八种情况: 000 s001 s010 0011 s100 s101 1110 s111 s 可以看出只有010,101是不稳定的.其他都是稳定的,且连续地出现了1或0,标记为 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- Spring 学习——Bean容器
Bean容器初始化 基础 org.springframework.beans org.springframework.context BeanFactory提供配置结构和基本功能,加载并初始化Bean ...
- Python3 tkinter基础 Canvas bind 鼠标左键点击时,在当前位置画椭圆形
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- 内核中的xenfs是什么?
答: 是一个xen虚拟机高性能搜索文件系统,它基于共享内存通信协议和共享缓冲区缓存.
- python 之 文件I/0
打开和关闭文件 open()函数 必须要open()内置函数打开一个文件,创建一个file对象,相关的方法才可以调用它进行读写. 语法 file object=open(file_name [,acc ...
- GPIO实验之c语言
上一章节进行实验使用的是汇编进行编程的,本次实验是使用c语言进行编写的. (1)点亮一个led灯 1)启动文件: crt.S .text .global _start _star ...
- PTA 7-1 整数分解为若干项之和(20 分)
7-1 整数分解为若干项之和(20 分) 将一个正整数N分解成几个正整数相加,可以有多种分解方法,例如7=6+1,7=5+2,7=5+1+1,….编程求出正整数N的所有整数分解式子. 输入格式: 每个 ...
- js数组常用方法,含es5
(1)基本的数组方法 1.join() Array.join()方法将数组中所有元素都转化为字符串并连接在一起,返回最后生成的字符串.可以自己指定分隔的符号,如果不指定,默认使用逗号 var arr ...
- 新建DataTable添加列添加行
新建空Table添加行和列 DataTable dt = new DataTable(); //创建空DataTable 1.添加列 dt.Columns.Add("序号", ty ...
- Log4j日志依赖
<!-- https://mvnrepository.com/artifact/log4j/log4j --><dependency> <groupId>log4j ...
- 如何连接oracle 12c可插拔数据库
启动根容器:[oracle@eric ~]$ export ORACLE_SID=cup[oracle@eric ~]$ sqlplus / as sysdbaSQL*Plus: Release 12 ...