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. Android - 单例模式(singleton)的使用

    单例模式(singleton)的使用 本文地址:http://blog.csdn.net/caroline_wendy 单例(singleton)是特殊的Java类,在创建实例时.一个类仅同意创建一个 ...

  2. Maven上传本地jar

    1. 将Jar包安装到本地仓库 -- DgroupId和DartifactId构成了该jar包在pom.xml的坐标, 对应依赖的DgroupId和DartifactId    -- Dfile表示需 ...

  3. Android中处理崩溃异常和记录日志(转)

    现在安装Android系统的手机版本和设备千差万别,在模拟器上运行良好的程序安装到某款手机上说不定就出现崩溃的现象,开发者个人不可能购买所有设备逐个调试,所以在程序发布出去之后,如果出现了崩溃现象,开 ...

  4. 特权级概述(哥子就想知道CPU是如何验证特权级的)GATE+TSS

    [0]README text description from orange's implemention of a os . [1]特权级概述 当当前代码段试图访问一个段或者门时,目标段的DPL将会 ...

  5. 【bootstrap】右侧sidebar不跟着内容滚动的异常

    移动开发需要依赖于Web服务的接口,但是写这个接口文档实在是比较繁琐,所以今天我就写了个包解析程序自动生成接口文档. 内容显示我是借鉴Bootstrap的官方教程http://v3.bootcss.c ...

  6. 消息队列Handler的用法

    下面是每隔一段时间就执行某个操作,直到关闭定时操作: final Handler handler = new Handler(); Runnable runnable = new Runnable() ...

  7. 补充ajax分页的代码

    1.主页代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...

  8. 用CMakeLists.txt组织工程

    1 一个工程会有多个CMakeLists.txt,如何组织这些CMakeLists.txt来构建一个工程? 1.1  最外层一个CMakeLists.txt,是总的CMakeList.txt,在这个里 ...

  9. iOS 跳转到Appstore的链接及二维码

    1.应用内部跳转到Appstore 1.跳转到应用详情 [[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"it ...

  10. 【题解】POJ1934 Trip (DP+记录方案)

    [题解]POJ1934 Trip (DP+记录方案) 题意: 传送门 刚开始我是这么设状态的(谁叫我DP没学好) \(dp(i,j)\)表示钦定选择\(i\)和\(j\)的LCS,然而你会发现这样钦定 ...