Codeforces Round #363 (Div. 2)->C. Vacations
1 second
256 megabytes
standard input
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:
- on this day the gym is closed and the contest is not carried out;
- on this day the gym is closed and the contest is carried out;
- on this day the gym is open and the contest is not carried out;
- 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.
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.
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.
4
1 3 2 0
2
7
1 3 3 2 1 2 3
0
2
2 2
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.
思路: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的更多相关文章
- 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 ...
- 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] ...
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- CodeForces 698A - Vacations (Codeforces Round #363 (Div. 2))
要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情 ...
- Codeforces Round #363 (Div. 2)
A题 http://codeforces.com/problemset/problem/699/A 非常的水,两个相向而行,且间距最小的点,搜一遍就是答案了. #include <cstdio& ...
- Codeforces Round #363 Div.2[111110]
好久没做手生了,不然前四道都是能A的,当然,正常发挥也是菜. A:Launch of Collider 题意:20万个点排在一条直线上,其坐标均为偶数.从某一时刻开始向左或向右运动,速度为每秒1个单位 ...
- Codeforces Round #363 (Div. 1) B. Fix a Tree 树的拆环
题目链接:http://codeforces.com/problemset/problem/698/B题意:告诉你n个节点当前的父节点,修改最少的点的父节点使之变成一棵有根树.思路:拆环.题解:htt ...
- 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 ...
- 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 ...
随机推荐
- 前台JSP页面独立化
一直从事Java WEB开发的过程中,当然要常常写JSP文件. 本人对JSP文件有些自己的想法. 页面要尽可能的简单,整洁,条理. js文件要尽可能地放到独立的js文件中,然后引用到当前的JSP文件中 ...
- 《CSS3秘笈》备忘录
第一部分 1. 类名称区分大小写:.special和.SPECIAL不一样 2. :focus 是通过单击或跳格集中在某个地方 3. ::selection 没有单冒号,被选中的文本[ 但是在I ...
- 《squid网卡代理的实现》RHEL6.3——条理清晰,步骤明确
网卡的代理和FQ差不多一个道理.ping 不通不代表不能上网. 实验的目的: 打开2台虚拟主机,一台2个网卡(这台为服务器):一台一个网卡: 2块网卡的服务器使用静态ip可以上网,也就是说网段为1的可 ...
- 一个Ctrl+V下的问题
对于电脑快捷键来说恐怕没什么比Ctrl+C和Ctrl+V更熟悉的了. 最近做了一个小程序,界面上有一个文本框,要做的事情就是把从别的地方复制内容后粘贴到文本框中,然后以自己处理后的格式显示出来. 为了 ...
- Oracle中排序列中值相同引发的问题(译)
This queston came up on the Oracle newsgroup a few days ago: 这个问题在Oracle的新闻中心被提出了一段时间: I have a tabl ...
- php 获取数组第一个值的方法分享
以下是对使用php实现获取数组第一个值的方法进行了详细的分析介绍,需要的朋友可以过来参考下 reset (PHP 3, PHP 4, PHP 5)reset -- 将数组的内部指针指向第一个单元 说明 ...
- ASP专栏——ASP生成静态文件(用于大量文章)
对于Web开发人员来说,生成静态文件这个概念并不陌生. 对于Web开发来说,如何能避免客户端访问时不停的查询数据库?现在比较常用的有两种方法,一种是使用缓存技术,将查询出来的结果缓存至缓存框架中,以后 ...
- linux学习之进程,线程和程序
程序.进程和线程的概念 1:程序和进 ...
- postgresql 开启远程访问
1.如果服务器启用了防火墙,需要在防火墙上开启 5432 端口. 2.修改 PostgreSQL 配置文件 postgresql.conf.postgresql.conf,Linux 配置文件所在路径 ...
- C#——中文转化成拼音
在KS系统中用到了中文转化成拼音的功能.通过查阅资料为下面是代码. /// <summary> /// MyConvert 的摘要说明 /// </summary> publi ...