Description

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.

Input

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 a1, a2, ..., an (0 ≤ ai ≤ 3) separated by space, where:

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

Output

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.

Sample Input

Input

4
1 3 2 0

Output

2

Input

7
1 3 3 2 1 2 3

Output

0

Input

2
2 2

Output

1

用k记录每天的状态,b[i]记录从第一天到第i天休息的天数,每一天的状态只与前一天有关,尽量保证能工作就不休息

 // 0 健身房关门   没比赛
// 1 健身房关门 有比赛
// 2 健身房开门 没比赛
// 3 健身房开门 有比赛
#include <cstdio>
int n,a[],k,i,b[];
int main()
{ while(scanf("%d",&n)!=EOF)
{
b[]=;
k=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i = ; i <= n ; i++)
{
if(a[i] == )
{
b[i]=b[i-]+;
k=;
}
else
{
if(a[i] == )
{
b[i]=b[i-];
k=-k;
}
else
{
if(a[i] == k)
{
b[i]=b[i-]+;
k=;
}
else
{
b[i]=b[i-];
k=a[i];
}
}
}
}
printf("%d\n",b[n]);
}
}

(贪心) Vacations 求休息的最少天数的更多相关文章

  1. 算法笔试题整理——升级蓄水池 && 字符串数字表达式计算值 && 求旅游完所有景点需要的最少天数 && 宝箱怪

    1. 小米笔试题——升级蓄水池 题目描述: 在米兔生活的二维世界中,建造蓄水池非常简单. 一个蓄水池可以用n个坐标轴上的非负整数表示,代表区间为[0-n]范围内宽度为1的墙壁的高度. 如下图1,黑色部 ...

  2. 【js】Leetcode每日一题-制作m束花所需的最少天数

    [js]Leetcode每日一题-制作m束花所需的最少天数 [题目描述] 给你一个整数数组 bloomDay,以及两个整数 m 和 k . 现需要制作 m 束花.制作花束时,需要使用花园中 相邻的 k ...

  3. LeetCode 1482. 制作 m 束花所需的最少天数

    LeetCode 1482. 制作 m 束花所需的最少天数 题目 给你一个整数数组 bloomDay,以及两个整数 m 和 k . 现需要制作 m 束花.制作花束时,需要使用花园中 相邻的 k 朵花 ...

  4. 1482. 制作 m 束花所需的最少天数

    2021-05-09 LeetCode每日一题 链接:https://leetcode-cn.com/problems/minimum-number-of-days-to-make-m-bouquet ...

  5. Vijos P1023Victoria的舞会3【贪心+DFS求强联通分量】

    链接:Click Me! P1023Victoria的舞会3 Accepted 标签:Victoria的舞会[显示标签] 描写叙述 Victoria是一位颇有成就的艺术家,他因油画作品<我爱北京 ...

  6. UVALive 6911 Double Swords (Set,贪心,求区间交集)

    补:华中VJ这个题目很多标程都不能AC了,包括我下面原本AC了的代码,再交就WA掉了,感觉是样例有问题呢-- 首先左边的是必须要选的,然后右边的需要注意,有些区间是可以舍掉的.1.区间里有两个不同的A ...

  7. 通过日期在js中求出判断间隔天数,周期等实现分享

    在我们在项目的时候,可能出现这样的一种情况,有一个开始时间和一个结束时间,而这两个时间用$('#StartTime').val(); 取出来的时候又是datetime 类型,我们需要求这个时间中的间隔 ...

  8. POJ 4020 NEERC John's inversion 贪心+归并求逆序对

    题意:给你n张卡,每张卡上有蓝色和红色的两种数字,求一种排列使得对应颜色数字之间形成的逆序对总数最小 题解:贪心,先按蓝色排序,数字相同再按红色排,那么蓝色数字的逆序总数为0,考虑交换红色的数字消除逆 ...

  9. HDU - 2037 今年暑假不AC 贪心(求序列中不重叠子序列的最大值问题)

    HDU2037 今年暑假不AC  贪心算法 大意: 每次测试数据输入一个n,然后输入n对的电视节目播放时间:开始时间及结束时间, 求这个人能看的最多的完整的节目数. 解题思路: 对于这道解题,是对每个 ...

随机推荐

  1. 我的spring cloud项目历程(2018.3~2018.9)

    前言 今天是9月17日,趁着山竹的临幸,得以在家里舒适的办公.项目从3月底开始,至今刚好半年.抽几十分钟,总结下半年的历程.对后面的项目,应该也有一点帮助吧. 学习前的七个问题 项目开始前,由于某些特 ...

  2. Python生成器实现斐波那契数列

    比如,斐波那契数列:1,1,2,3,5,8,13,21,34.... 用列表生成式写不出来,但是我们可以用函数把它打印出来: def fib(number): n, a, b = 0, 0, 1 wh ...

  3. [SDOI2016]墙上的句子

    题目描述 考古学家发现了一堵写有未知语言的白色墙壁,上面有一个n行m列的格子,其中有些格子内被填入了某个A至Z的大写字母,还有些格子是空白的. 一直横着或竖着的连续若干个字母会形成一个单词,且每一行的 ...

  4. [BZOJ1381]Knights

    Description 在一个N*N的棋盘上,有些小方格不能放骑士,棋盘上有若干骑士,任一个骑士不在其它骑士的攻击范围内,请输出最多可以放多少个骑士. 骑士攻击的点如中国象棋中的马,可以攻击8个点. ...

  5. Windows环境下修改Oracle实例监听IP地址

    Windows环境下修改Oracle实例监听IP地址. 配置文件路径:<ORACLE_HOME>\NETWORK\ADMIN 如:C:\Oracle11gR2\product\11.2.0 ...

  6. this关键字的构造方法的使用

    package com.wh.Object3; public class this_Demo { private String name; private double price; private ...

  7. 转】R利剑NoSQL系列文章 之 Hive

    原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/3/ 感谢! Posted: Jul 27, 2013 Ta ...

  8. 移动端UI自动化Appium测试——DesiredCapabilities参数配置及含义

    一.DesiredCapabilities的作用: 负责启动服务端时的参数设置,启动session的时候是必须提供的. Desired Capabilities本质上是key value的对象,它告诉 ...

  9. h5学习-h5嵌入android中

    嵌入Android中的h5界面: 将此页面复制到android项目中的assets目录下边: <!DOCTYPE html> <html lang="en"> ...

  10. Java数据类型和MySql数据类型对应一览 [转]

    类型名称 显示长度 数据库类型 JAVA类型 JDBC类型索引(int) 描述             VARCHAR L+N VARCHAR java.lang.String 12   CHAR N ...