CF698A.Vacations

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:

  1. on this day the gym is closed and the contest is not carried out;
  2. on this day the gym is closed and the contest is carried out;
  3. on this day the gym is open and the contest is not carried out;
  4. on this day the gym is open and the contest is carried out.

On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).

Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.

瓦西娅有 nn 天假期!因此他决定提升自己的 IT 技能并进行体育锻炼。瓦西娅知道这 nn 天中每一天的如下信息:健身房是否开放,以及当天网上是否举行编程竞赛。对于第 ii 天,共有以下四种情况:

  1. 当天健身房关闭,且网上不举行竞赛;
  2. 当天健身房关闭,但网上举行竞赛;
  3. 当天健身房开放,但网上不举行竞赛;
  4. 当天健身房开放,且网上举行竞赛。

在每一天,瓦西娅可以做以下三件事之一:休息;若当天举行竞赛,则可参加竞赛;若当天健身房开放,则可进行体育锻炼。

请找出瓦西娅需要休息的最少天数(即:他既不锻炼也不参赛的天数)。瓦西娅唯一的限制是:他不想连续两天做相同的活动——也就是说,他不会连续两天锻炼,也不会连续两天参赛。

输入格式

The first line contains a positive integer n (1 ≤ n ≤ 100) — the number of days of Vasya's vacations.

The second line contains the sequence of integers _a_1, _a_2, ..., a__n (0 ≤ a__i ≤ 3) separated by space, where:

  • a__i equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
  • a__i equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
  • a__i equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out;
  • a__i equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.

第一行包含一个正整数 nn(1≤n≤1001 \leq n \leq 100)—— 表示瓦夏假期的天数。

第二行包含由空格分隔的整数序列 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤30 \leq a_i \leq 3),其中:

  • 若 ai=0a_i = 0,表示在假期的第 ii 天,健身房关闭且不举办比赛;
  • 若 ai=1a_i = 1,表示在假期的第 ii 天,健身房关闭但举办比赛;
  • 若 ai=2a_i = 2,表示在假期的第 ii 天,健身房开放但不举办比赛;
  • 若 ai=3a_i = 3,表示在假期的第 ii 天,健身房开放且举办比赛。

输出格式

Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:

  • to do sport on any two consecutive days,
  • to write the contest on any two consecutive days.

输出瓦西娅最少需要休息的天数。注意瓦西娅拒绝:

  • 在任意连续两天进行体育运动,
  • 在任意连续两天参加竞赛。

输入输出样例

  • 输入#1

    4
    1 3 2 0

    输出#1

    2
  • 输入#2

    7
    1 3 3 2 1 2 3

    输出#2

    0
  • 输入#3

    2
    2 2

    输出#3

    1

说明/提示

In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.

In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.

In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.

在第一个测试用例中,瓦西娅可以在第 1 天参加比赛,并在第 3 天进行体育锻炼。因此,他仅需休息 2 天。

在第二个测试用例中,瓦西娅应在第 1、3、5 和 7 天参加比赛,在其余天数进行体育锻炼。因此,他将一天也不休息。

在第三个测试用例中,瓦西娅只能在第 1 天或第 2 天中的一天进行体育锻炼。他不能在两天都进行体育锻炼,否则将违反其限制条件。因此,他仅需休息 1 天。

输入解题思路,AI测评打分。不知道怎么写?

首页