Codeforces 590A Median Smoothing
来源:互联网 发布:电信网络机顶盒怎么设置 编辑:程序博客网 时间:2024/05/17 08:04
题意; 给你一个0 1序列,首尾元素保持不变,从2-n-1,变成a[i-1]+a[i]+a[i-1]/2,问经过多少次不再改变,求出最后的序列。
分析:一个元素可以改变,只有他和左右的都不相同才行,这样原来的序列,就可以分成好多段01序列段,只有这种01交替变换的才能够改变,不是这种串不能改变,这样改变的次数就是最长的01变化的串。改变的时候如果首尾元素相同,全部就变成首尾元素,如果首尾元素不同,前一半变成首元素,后一半变成尾元素。
#include<bits/stdc++.h>using namespace std;#define LL long longconst int maxn=500005;int ans[maxn],a[maxn];int main(){ int n; scanf("%d",&n); //getchar(); int cnt=0; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } int len=0; for(int i=0;i<n;i++){ ans[i]=a[i]; int j; for( j=i;j<n-1;j++){ if(a[j]==a[j+1])break; } int len=j-i-1; int mid=(j+i)/2; // cout<<mid<<endl; for(int k=i;k<=j;k++){ if(k<mid)ans[k]=a[i]; else ans[k]=a[j]; } if(cnt<len)cnt=len; i=j; // cnt=max(cnt,len); } if(cnt<len)cnt=len; // cnt=max(cnt,len); printf("%d\n",cnt/2+cnt%2); for (int i = 0; i < n; ++i) { if (i != 0) putchar(' '); printf("%d", ans[i]); } puts(""); return 0;}
0 0
- Codeforces 590A Median Smoothing
- Codeforces 590 A:Median Smoothing
- CodeForces-590A Median Smoothing
- CodeForces 590A Median Smoothing
- CodeForces 590A Median Smoothing
- Codeforces 590A Median Smoothing
- Codeforces 590A Median Smoothing(暴力)
- 590 A. Median Smoothing
- codeforces 591 C. Median Smoothing
- Code Forces 590 A. Median Smoothing(机智)
- codeforces#327-C.Median Smoothing-规律题
- Codeforces #591 C Median Smoothing(思维)
- codeforces#327->C.Median Smoothing(规律题 )
- 【22.70%】【codeforces 591C】 Median Smoothing
- Codeforces 591C Median Smoothing【思维】
- Codeforces Round #327 (Div. 1) A题: Median Smoothing [规律题]
- Codeforces Round #327 (Div. 2) C - Median Smoothing
- Codeforces Round #327 (Div. 2) C. Median Smoothing 暴力
- HID读写过程
- nodejs 安装 linux
- 自定义控件-实现带清空功能的EditText
- 动态规划算法解决0-1背包问题
- 已知两个链表head1 和head2 各自有序,请把它们合并成一个链表依然有序。使用非递归方法以及递归方法。
- Codeforces 590A Median Smoothing
- python自学之列表、元组
- 089.Struct Array 结构体数组
- python标准库
- Redmine如何自定义问题状态
- 一个简化版的仿微信聊天界面UI
- 6.4 键盘消息和字符集
- 专访左程云:5年刷题大牛分享算法学习之道
- ARM Linux 3.x的设备树(Device Tree)