Median Smoothing

#include<bits/stdc++.h>
using namespace std;
const int maxn=500011;
const int inf=1<<27;
#define LL long long
#define P pair<int,int>
#define pb push_back
#define cl(a,b) memset(a,b,sizeof(a));

int a[maxn];
int main(){
    int n;
    while(~scanf("%d",&n)){
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        int L=0,R=0;
        int ans=0;
        for(int i=1;i<n;i++){
            while(a[R]!=a[R+1]&&R+1<n)R++;
            int l=L+1,r=R-1;
            int tmp=0;
            while(l<=r){
                a[l]=a[L];a[r]=a[R];
                l++;r--;
                tmp++;
            }
            L=R=i;
            ans=max(ans,tmp);
        }

        printf("%d\n",ans);
        for(int i=0;i<n;i++){
            printf("%d%c",a[i],i==n-1?‘\n‘:‘ ‘);
        }
    }
    return 0;
}
时间: 2024-11-03 21:58:43

Median Smoothing的相关文章

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. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the

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

C. Median Smoothing A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and eng

CodeForces 590A Median Smoothing

A schoolboy named Vasya loves reading books on programming and mathematics. He has recently read an encyclopedia article that described the method of median smoothing (or median filter) and its many applications in science and engineering. Vasya like

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

http://codeforces.com/problemset/problem/590/A: 在CF时没做出来,当时直接模拟,然后就超时喽. 题意是给你一个0 1串然后首位和末位固定不变,从第二项开始到倒数第二项,当前的a[i]=(a[i-1],a[i],a[i+1])三项排序后的中间项,比如连续3项为 1 0 1,那么中间的就变为1,然后题目让你输出达到稳定状态时所需的最小步数,不能的话输出-1. 无论给你啥数列,都能达到稳态.所以不可能输出-1: 还有一开始就稳定不变,或经过几次变换而稳定

【OpenCV教程之九】平滑/模糊图片 Smooth / Blur Images及 彩色图转 灰度图和二值化

这一节,谈一谈如何对图像进行平滑,也可以叫做模糊.平滑图像的主要目的是减少噪声,这样采用平滑图像来降低噪声是是非常常见的预处理方法. 1.归一化滤波平滑-Homogeneous Smoothing 2.高斯滤波平滑-Gaussian Smoothing 3.中值滤波平滑-Median Smoothing 4.双边滤波平滑-Bilateral Smoothing 平滑是通过滑动窗口(内核或过滤器)扫描整个图像窗口,计算每个像素的基于核的值的和重叠的原始图像的像素的值的值来完成.这个过程在数学上称为

Cubic and Smoothing Splines in R

原文链接:http://tecdat.cn/?p=9670 样条线是拟合非线性模型并从数据中学习非线性相互作用的一种方法. 三次样条 三次样条 具有连续的一阶和二阶导数. 我们通过应用基础函数来变换变量  并使用这些变换后的变量拟合模型, 向模型添加非线性, 使样条曲线能够拟合更平滑 . #loading the Splines Packages require(splines) #ISLR contains the Dataset require(ISLR) attach(Wage) #att

LeetCode OJ 4. Median of Two Sorted Arrays

There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1: nums1 = [1, 3] nums2 = [2] The median is 2.0 Example 2: nums1 = [1,

leetcode笔记:Find Median from Data Stream

一. 题目描述 Median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value. Examples: [2,3,4] , the median is 3 [2,3], the median is (2 + 3) / 2 = 2.5 De

zoj Median (multiset)

Median Time Limit: 5 Seconds      Memory Limit: 65536 KB The median of m numbers is after sorting them in order, the middle one number of them ifm is even or the average number of the middle 2 numbers if m is odd. You have an empty number list at fir