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

Copy
5
1 1 2 2 2

Sample Output 1 Copy

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

Copy
3
1 2 1

Sample Output 2 Copy

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

Copy
5
1 1 1 1 1

Sample Output 3 Copy

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

Copy
14
1 2 2 3 3 3 4 4 4 4 1 2 3 4

Sample Output 4 Copy

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的更多相关文章

  1. AtCoder Grand Contest 016 B - Colorful Hats

    题目传送门:https://agc016.contest.atcoder.jp/tasks/agc016_b 题目大意: 有\(N\)只猫,每只猫头上带着一个帽子,帽子有颜色,现在告诉你每只猫能看到的 ...

  2. AtCoder Grand Contest 026 (AGC026) E - Synchronized Subsequence 贪心 动态规划

    原文链接https://www.cnblogs.com/zhouzhendong/p/AGC026E.html 题目传送门 - AGC026E 题意 给定一个长度为 $2n$ 的字符串,包含 $n$ ...

  3. AtCoder Grand Contest 026 D - Histogram Coloring

    一列中有两个连续的元素,那么下一列只能选择选择正好相反的填色方案(因为连续的地方填色方案已经确定,其他地方也就确定了) 我们现将高度进行离散化到Has数组中,然后定义dp数组 dp[i][j] 表示前 ...

  4. 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 ...

  5. AtCoder Grand Contest #026 B - rng_10s

    Time Limit: 2 sec / Memory Limit: 1024 MB Score : 600600 points Problem Statement Ringo Mart, a conv ...

  6. AtCoder Grand Contest 012 D Colorful Balls

    题意: 有N个球排成一行,第i个球颜色为ci, 权为wi, 如果两个同色球权值和 <= X 则它们可以交换: 如果两个异色球权值和 <= Y 则它们可以交换:不限制交换次数,求能到达的颜色 ...

  7. Atcoder Grand Contest 026 (AGC026) F - Manju Game 博弈,动态规划

    原文链接www.cnblogs.com/zhouzhendong/AGC026F.html 前言 太久没有发博客了,前来水一发. 题解 不妨设先手是 A,后手是 B.定义 \(i\) 为奇数时,\(a ...

  8. AtCoder Grand Contest 004

    AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条 ...

  9. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

随机推荐

  1. Java开启/关闭tomcat服务器

    © 版权声明:本文为博主原创文章,转载请注明出处 通过java代码实现Tomcat的开启与关闭 1.项目结构 2.CallTomcat.java package com.calltomcat.test ...

  2. MySQL系列:innodb源代码分析之线程并发同步机制

    innodb是一个多线程并发的存储引擎,内部的读写都是用多线程来实现的,所以innodb内部实现了一个比較高效的并发同步机制. innodb并没有直接使用系统提供的锁(latch)同步结构,而是对其进 ...

  3. JAVA学习第二十五课(多线程(四))- 单例设计模式涉及的多线程问题

    一.多线程下的单例设计模式 利用双重推断的形式解决懒汉式的安全问题和效率问题 //饿汉式 /*class Single { private static final Single t = new Si ...

  4. 一步一步实现视频播放器client(二)

    实现主体界面:                 222.png (64.46 KB, 下载次数: 0) 下载附件  保存到相冊 前天 21:02 上传 比較常见的一种布局.以下几个button.点击后 ...

  5. 小东和三个朋友一起在楼上抛小球,他们站在楼房的不同层,假设小东站的楼层距离地面N米,球从他手里自由落下,每次落地后反跳回上次下落高度的一半,并以此类推知道全部落到地面不跳,求4个小球一共经过了多少米?(数字都为整数) 给定四个整数A,B,C,D,请返回所求结果。

    include #include<vector> using namespace std; class Balls { public: int calcDistance(int A, in ...

  6. JavaScript中setInterval用法

    setInterval动作的作用是在播放动画的时,每隔一定时间就调用函数,方法或对象.可以使用本动作更新来自数据库的变量或更新时间显示. setInterval动作的语法格式如下:setInterva ...

  7. HIbernate 注解 mappedBy 与 inverse

    hibernate中 配置文件中的inverse属性意思就是放弃控制权 ,主导权由对方控制,也就是说 我方进行的删除等操作不会影响到对方 即使设置了cascadeType.ALL 这个解释其实就是hi ...

  8. maven工作的过程

    1 建立各个module之间的依赖关系 2 越底层的依赖的module先生成 3 下载远程库中的依赖 4 先生成本地被依赖的module 问题是,如何保证本次module和远程库中的包不重名?

  9. 【题解】 CF11D A Simple Task

    [题解] CF11D A Simple Task 传送门 \(n \le 20\) 考虑状态压缩\(dp\). 考虑状态,\(dp(i,j,O)\)表示从\(i\)到\(j\)经过点集\(O\)的路径 ...

  10. 一起来学linux:SAMBA服务器搭建

    前面介绍的NFS服务器的用来linux和linux系统之间共享文件和目录的,那如果是linux和windows之间需要共享修改文件该如何操作呢.这据需要用到SAMBA系统.我们首先来看下SAMBA系统 ...