AtCoder Grand Contest #026 A - Colorful Slimes 2
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 200200 points
Problem Statement
Takahashi lives in another world. There are slimes (creatures) of 1000010000 colors in this world. Let us call these colors Color 1,2,...,100001,2,...,10000.
Takahashi has NN slimes, and they are standing in a row from left to right. The color of the ii-th slime from the left is aiai. If two slimes of the same color are adjacent, they will start to combine themselves. Because Takahashi likes smaller slimes, he has decided to change the colors of some of the slimes with his magic.
Takahashi can change the color of one slime to any of the 1000010000 colors by one spell. How many spells are required so that no slimes will start to combine themselves?
Constraints
- 2≤N≤1002≤N≤100
- 1≤ai≤N1≤ai≤N
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
NN
a1a1 a2a2 ...... aNaN
Output
Print the minimum number of spells required.
Sample Input 1 Copy
5
1 1 2 2 2
Sample Output 1 Copy
2
For example, if we change the color of the second slime from the left to 44, and the color of the fourth slime to 55, the colors of the slimes will be 1,4,2,5,21,4,2,5,2, which satisfy the condition.
Sample Input 2 Copy
3
1 2 1
Sample Output 2 Copy
0
Although the colors of the first and third slimes are the same, they are not adjacent, so no spell is required.
Sample Input 3 Copy
5
1 1 1 1 1
Sample Output 3 Copy
2
For example, if we change the colors of the second and fourth slimes from the left to 22, the colors of the slimes will be 1,2,1,2,11,2,1,2,1, which satisfy the condition.
Sample Input 4 Copy
14
1 2 2 3 3 3 4 4 4 4 1 2 3 4
Sample Output 4 Copy
4 对于连续相同的只需要把一半的换颜色就可以了。
代码:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a = 0;
int b = 0;
int c = 0;
int ans = 0;
for(int i = 0;i < n;i ++) {
b = in.nextInt();
if(a == b)c ++;
else {
ans += c / 2;
c = 1;
}
a = b;
}
ans += c / 2;
System.out.println(ans);
}
}
AtCoder Grand Contest #026 A - Colorful Slimes 2的更多相关文章
- AtCoder Grand Contest 016 B - Colorful Hats
题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_b 题目大意: 有\(N\)只猫,每只猫头上带着一个帽子,帽子有颜色,现在告诉你每只猫能看到的 ...
- AtCoder Grand Contest 026 (AGC026) E - Synchronized Subsequence 贪心 动态规划
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ ...
- AtCoder Grand Contest 026 D - Histogram Coloring
一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...
- AtCoder Grand Contest #026 C - String Coloring
Time Limit: 3 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement You are given a st ...
- AtCoder Grand Contest #026 B - rng_10s
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement Ringo Mart, a conv ...
- AtCoder Grand Contest 012 D Colorful Balls
题意: 有N个球排成一行,第i个球颜色为ci, 权为wi, 如果两个同色球权值和 <= X 则它们可以交换: 如果两个异色球权值和 <= Y 则它们可以交换:不限制交换次数,求能到达的颜色 ...
- Atcoder Grand Contest 026 (AGC026) F - Manju Game 博弈,动态规划
原文链接www.cnblogs.com/zhouzhendong/AGC026F.html 前言 太久没有发博客了,前来水一发. 题解 不妨设先手是 A,后手是 B.定义 \(i\) 为奇数时,\(a ...
- AtCoder Grand Contest 004
AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条 ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
随机推荐
- Atitit.ati dwr的原理and设计 attilax 总结 java php 版本号
Atitit.ati dwr的原理and设计 attilax 总结 java php 版本号 1. dwr的长处相对于ajax来说.. 1 2. DWR工作原理 1 3. Dwr的架构 2 4. 自己 ...
- easyui datagrid自己定义操作列
通过formatter方法给Jquery easyui 的datagrid 每行添加操作链接 我们都知道Jquery的EasyUI的datagrid能够加入而且自己定义Toolbar. 这样我们选择一 ...
- 求解复数组 中模较大的N个数
//求解复数组 中模较大的N个数 void fianN_Complex(Complex outVec[], int& len, std::vector<int>& inde ...
- 为备考二级C语言做的代码练习---辅导资料《C语言经典编程282例》--(1)
因为二级考试的时候用的C语言编译器是VC++6.0 真是日了狗了 用这个编译器 这是我第2个C编译器吧,第一个用的是啊哈C编译器..第二个是VS++6.0 然后在win下用VS2013感觉挺不错的 毕 ...
- iostat命令具体解释——linux性能分析
之前总结uptime和free命令,今天继续来总结一下iostat.给自己留个笔记.同一时候也希望对大家实用. 版本号信息: sysstat version 9.0.4 (C) S ...
- 基于RedHat发行的Apache Tomcat本地提权漏洞
描述 Tomcat最近总想搞一些大新闻,一个月都没到,Tomcat又爆出漏洞.2016年10月11日,网上爆出Tomcat本地提权漏洞,漏洞编号为CVE-2016-5425.此次受到影响的主要是基于R ...
- 8148之更换摄像头出现异常---REISZER OVERFLOW OCCURED: RESTARTING
my iss config as: rsz_reg->SRC_VSZ = 1079;//715; rsz_reg->SRC_HSZ = 1919;//1277; rszA_reg ...
- 初识python轻量web框架flask
1.使用pip安装Python包 大多数Python包都使用pip实用工具安装,使用pyvenv创建的虚拟环境会自动安装pip. 1.使用pip安装Flask(其它Python包同理) pip ins ...
- 2017-2018-1 20179209《Linux内核原理与分析》第五周作业
一.实验:使用库函数API和C代码中嵌入汇编代码两种方式使用同一个系统调用 环境说明 实验环境为 Ubuntu16.10 和 实验楼环境. 选择39号系统调用实验.39号系统调用为mkdir系统调用. ...
- 响应式布局【3】 --- bootstrap
本片文章主要讲解Bootstrap中如何实现响应式布局的. 参考资料&内容来源: https://code.ziqiangxuetang.com/bootstrap/bootstrap-gri ...