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 ...
随机推荐
- 如何对正在运行的进程,进行heap profile
简单来说, 就是先preload上tcmalloc, 日常用用没啥问题, 当感觉出现问题时, gdb attach 上, 然后执行 call HeapProfilerStart("xxx&q ...
- 每天一个linux命令:free
1.命令简介 free (free) 命令可以显示Linux系统中空闲的.已用的物理内存及swap内存,及被内核使用的buffer. 2.用法 free [-b | -k | -m | -g | -h ...
- sed用法去除行首和行末的中括号
sed去掉行首和行末的中括号: sed -i 's:^\[::; s:\]$::;' newtrace_nlp.log.2018-08-02.bak 其余可依次类推.
- 【iCore4 双核心板_uC/OS-II】例程十:信号量集
一.实验说明: 在实际应用中,任务常常需要与多个事件同步,即要根据多个信号量组合作用的结果来决定任务的运行方式.UCOSII为了实现多个信号量组合的功能定义了一种特殊的数据结构——信号量集. 二.实验 ...
- ubuntu install wiznote
sudo add-apt-repository ppa:wiznote-team #添加官方源 sudo apt-get update #更新源 sudo apt-get install wiznot ...
- iOS电量获取
一.Ios获取方法 Instrument电量工具获取 操作步骤: a) 手机不能连接数据线,kill掉后台所有app进程 b) 点击设置,选择开发,点击Logging,开启Energy,点击Start ...
- Swing与AWT在事件模型处理上是一致的。
Swing与AWT在事件模型处理上是一致的. Jframe实际上是一堆窗体的叠加. Swing比AWT更加复杂且灵活. 在JDK1.4中,给JFRAME添加Button不可用jf.add(b).而是使 ...
- 我们正在招聘java工程师,想来美团工作吗?
我们希望你有? 1.3年以上Java服务器开发经验,精通Java及面向对象设计开发,熟悉主流web框架 2.熟悉网络编程,熟悉TCP/IP协议,熟悉互联网应用协议 3.有大规模分布式系统设计与开发经验 ...
- MySQL 大表数据定期归档
数据库有一张表数据量很大,真正WEB项目只用到一个月内的数据,因此把一个月前的旧数据定期归档. 1 - 创建一个新表,表结构和索引与旧表一模一样 create table table_news lik ...
- 2. ansible-playbook 条件语句-内部变量使用
内部变量指的是把变量定义在playbook里面或者是执行结果作为变量 循环语句-标准Loops [root@LeoDevops playb]# cat p_loop.yaml - hosts: u12 ...