C. Vacations
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.
Examples
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
Note

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.

 思路:a[i]有四种情况,0的话直接休息,1或2的话只要它不等于前一个a[i]就不休息,3的话,a[i]就等于3-a[i-1];

 

 #include<bits/stdc++.h>
using namespace std;
int main () {
int n,sum;
cin>>n;
int a[n];
for(int i=; i<=n; i++) {
cin>>a[i];
if(!a[i])
sum++;
else if(a[i]==a[i-]&&a[i]<) {
a[i]=;
sum++;
} else if(a[i]==)
a[i]=-a[i-];
}
cout<<sum<<endl;
return ;
}

Codeforces Round #363 (Div. 2)->C. Vacations的更多相关文章

  1. Codeforces Round #363 (Div. 2) C. Vacations(DP)

    C. Vacations time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. Codeforces Round #363 (Div. 2) C. Vacations —— DP

    题目链接:http://codeforces.com/contest/699/problem/C 题解: 1.可知每天有三个状态:1.contest ,2.gym,3.rest. 2.所以设dp[i] ...

  3. Codeforces Round 363 Div. 1 (A,B,C,D,E,F)

    Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...

  4. CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))

    要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情 ...

  5. Codeforces Round #363 (Div. 2)

    A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...

  6. Codeforces Round #363 Div.2[111110]

    好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...

  7. Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环

    题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...

  8. Codeforces Round #363 (Div. 2) A、B、C

    A. Launch of Collider time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #363 (Div. 2) C

    Description Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasy ...

随机推荐

  1. 20140527-ASP.NET中尖括号百分号用法

    1.<%=%> 里面放的变量名,如:<div><h1>Hello World</h1><p>Welcome to Beginning ASP ...

  2. JSON字符串和js对象转换

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON js数据类型: 字符串.数字 ...

  3. 安装MySQL软件

    安装MySQL软件(绿色版) ① 解压软件包 ② 更改文件夹名称为mysql并复制到/usr/local文件夹下 ③ 使用cd指令进入/usr/local/mysql文件夹,使用ls –l查看 查看后 ...

  4. java虚拟机理解探索1

    以下内容源于个人对<深入java虚拟机>的理解总结 基本概念: java虚拟机可以指一种抽象规范,也可以指一种具体实现,亦可以指一个java虚拟机实例. 虚拟机生命周期: 一个java虚拟 ...

  5. 杭电ACM2091--空心三角形

    http://acm.hdu.edu.cn/showproblem.php?pid=2091 scanf 和 printf的输入输出功能并不强大.有时候我们需要清空输入输出流,所以一定切记getcha ...

  6. WordPress 主题开发 - (三) 开发工具 待翻译

    Before we get started building any WordPress Theme, we’re going to need to get our development tools ...

  7. php + apache + mysql环境搭建

    别人写的很好,若是不改变php默认访问路径的话,能够成功搭建是没问题的 http://www.cnblogs.com/pharen/archive/2012/02/06/2340628.html

  8. Qt在VS2010的安装与配置

    1. 下载Qt的安装包和VS2010的Qt插件 2. 安装Qt SDK 点击下载安装包,一路回车即可,主要注意Qt的安装路径最好安装在全英文路径而且中间没有空格, 安装好后,可以运行开始菜单里面的Qt ...

  9. 自定义一个WPF的PathButton

    一.背景 做项目时总是少不了Button,但是普通的Button大家都不喜欢用,总是想要自定义的Button,正好项目中用到不要边框的Button,并且是形状也是根据功能不同而变化的,并且窗口程序是会 ...

  10. linux下的汇编环境搭建(nasm)

    第一步:先判断系统是否已经安装了nasm--------------->打开终端,执行whereis nasm :如果显示nasm: /usr/bin/nasm ,则已经安装:如果只显示nasm ...