国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Codeforces 699 C. Vacations ( 貪心

2019-11-14 12:56:45
字體:
來源:轉載
供稿:網友
C. Vacationstime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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.

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. ExamplesInput
41 3 2 0Output
2Input
71 3 3 2 1 2 3Output
0Input
22 2Output
1Note

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.

題意:: 一個人在一天內有四種選擇

休息,運動||休息,工作||休息,運動||工作 工作或者運動不能連續超過兩天,求最短的休息時間 重點就是不要連續超過兩天就可以 數據比較小,暴力就可以AC了

#include<stdio.h>int arr[105];int main(){ int n; while(~scanf("%d",&n)) { for(int i = 0;i < n; i++) scanf("%d",&arr[i]); int k = 0, flag = 0; for(int i = 0;i < n; i++) { if(arr[i] == 0) { k++; flag = 0; } else if(arr[i]==1 || arr[i]==2) { if(flag == arr[i]) { k++; flag = 0; } else flag =arr[i]; } else { if(flag == 1) { flag = 2; } else if(flag == 2) { flag = 1; } } } printf("%d/n",k); }return 0;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 扎鲁特旗| 韶山市| 五大连池市| 永和县| 陆川县| 囊谦县| 浦城县| 绥滨县| 安平县| 盐边县| 文化| 西华县| 富平县| 阿拉善盟| 绥滨县| 荣成市| 华坪县| 仁寿县| 大英县| 泗水县| 瑞昌市| 九龙坡区| 江陵县| 金川县| 开封县| 于田县| 上高县| 秦安县| 上饶县| 广东省| 杂多县| 桃园市| 九台市| 凤阳县| 阳新县| 界首市| 开封县| 固阳县| 遵义县| 蓬溪县| 顺昌县|