Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]
题目链接:https://codeforces.com/contest/1090/problem/M
There are n houses along the road where Anya lives, each one is painted in one of k possible colors.
Anya likes walking along this road, but she doesn't like when two adjacent houses at the road have the same color. She wants to select a long segment of the road such that no two adjacent houses have the same color.
Help Anya find the longest segment with this property.
Input
The first line contains two integers n and k — the number of houses and the number of colors (1≤n≤100000, 1≤k≤100000).
The next line contains n integers a1,a2,…,an — the colors of the houses along the road (1≤ai≤k).
Output
Output a single integer — the maximum number of houses on the road segment having no two adjacent houses of the same color.
Example
input
8 3
1 2 3 3 2 1 2 2
output
4
Note
In the example, the longest segment without neighboring houses of the same color is from the house 4 to the house 7. The colors of the houses are [3,2,1,2] and its length is 4 houses.
题意:
路边有 $n$ 座房子,每座房子有可能涂上 $k$ 种颜色中的一种。Anya不喜欢相邻两座房子有相同颜色,因此要选择路上最长的一段,使得这一段上所有相邻的房子都满足颜色不同。
题解:
$O(n)$ 维护当前段长度和最长长度即可。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int n,k,a[maxn];
int main()
{
cin>>n>>k;
int res=;
for(int i=,len;i<=n;i++)
{
scanf("%d",&a[i]);
if(i== || a[i]==a[i-]) len=;
else len++;
res=max(len,res);
}
cout<<res<<endl;
}
Codeforces 1090M - The Pleasant Walk - [签到水题][2018-2019 Russia Open High School Programming Contest Problem M]的更多相关文章
- Codeforces 1090A - Company Merging - [签到水题][2018-2019 Russia Open High School Programming Contest Problem A]
题目链接:https://codeforces.com/contest/1090/problem/A A conglomerate consists of n companies. To make m ...
- Codeforces 1090D - Similar Arrays - [思维题][构造题][2018-2019 Russia Open High School Programming Contest Problem D]
题目链接:https://codeforces.com/contest/1090/problem/D Vasya had an array of n integers, each element of ...
- Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]
题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- Educational Codeforces Round 7 A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/622/problem/A Description Consider the ...
- codeforces 677A A. Vanya and Fence(水题)
题目链接: A. Vanya and Fence time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces Testing Round #12 A. Divisibility 水题
A. Divisibility Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/597/probl ...
- Codeforces Beta Round #37 A. Towers 水题
A. Towers 题目连接: http://www.codeforces.com/contest/37/problem/A Description Little Vasya has received ...
- CodeForces 690C1 Brain Network (easy) (水题,判断树)
题意:给定 n 条边,判断是不是树. 析:水题,判断是不是树,首先是有没有环,这个可以用并查集来判断,然后就是边数等于顶点数减1. 代码如下: #include <bits/stdc++.h&g ...
随机推荐
- libreoffice python 操作word及excel文档
1.开始.关闭libreoffice服务: 开始之前同步字体文件时间,是因为创建soffice服务时,服务会检查所需加载的文件的时间,如果其认为时间不符,则其可能会重新加载,耗时较长,因此需事先统一时 ...
- 关于docker 意外停止,重新快速启动措施
1. 我们要重启这个镜像,需要知道这个镜像ID,类似这个: 7079ff99e10ac326726a364348853c0e508cad8ce00ae970f3c800f172a40252 那么你可以 ...
- mysql查询前几条记录
#My SQL 取前多少条select * from table LIMIT 5,10; #返回第6-15行数据 select * from table LIMIT 5; #返回前5行 select ...
- grokking deep learning
https://www.manning.com/books/grokking-deep-learning?a_aid=grokkingdl&a_bid=32715258
- idea 自动导入
- java使用代理请求https
我本来在我本机写的代码,本机电脑是可以连外网没限制,对于https和http都可以.但是放在linux服务器上后,因为VM限制了不能访问外网,而且有ssl验证所以就一直报错,要么是连不上线上请求,要么 ...
- Linux操作环境下配置MMIX环境
一.概述 MMIX用途:高德纳写的<计算机程序设计艺术>,使用 MMIXAL 来编写代码,解释算法. 环境:Ubuntu 桌面版18.04. 二.操作步骤 1,创建MMIX文件夹并切入该文 ...
- 第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置
第四百零二节,Django+Xadmin打造上线标准的在线教育平台—生产环境部署,uwsgi安装和启动,nginx的安装与启动,uwsgi与nginx的配置文件+虚拟主机配置 软件版本 uwsgi- ...
- myeclipse及Eclipse中.classpath、.project、.settings、.mymetadata(myeclipse特有)介绍
引言 今天在创建java项目的时候遇到了很多的错误,在解决的过程中遇到了一些根本不知道什么作用的文件,然后按照网上的一些做法可以将问题解决,但是这也说明我们在学习的时候很多基础和细节的地方是我们薄弱的 ...
- Ubuntu下Ansible安装和使用
Ansible是一个批量部署的工具 参考:Ansible中文权威指南 1.安装 sudo apt-get install software-properties-common sudo apt-add ...