标签:
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 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:
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
4
1 3 2 0
2
7
1 3 3 2 1 2 3
0
2
2 2
1
1 // 0 健身房关门 没比赛 2 // 1 健身房关门 有比赛 3 // 2 健身房开门 没比赛 4 // 3 健身房开门 有比赛 5 #include <cstdio> 6 int n,a[150],k,i,b[150]; 7 int main() 8 { 9 10 while(scanf("%d",&n)!=EOF) 11 { 12 b[0]=0; 13 k=0; 14 for(int i=1;i<=n;i++) 15 { 16 scanf("%d",&a[i]); 17 } 18 for(int i = 1 ; i <= n ; i++) 19 { 20 if(a[i] == 0) 21 { 22 b[i]=b[i-1]+1; 23 k=0; 24 } 25 else 26 { 27 if(a[i] == 3) 28 { 29 b[i]=b[i-1]; 30 k=3-k; 31 } 32 else 33 { 34 if(a[i] == k) 35 { 36 b[i]=b[i-1]+1; 37 k=0; 38 } 39 else 40 { 41 b[i]=b[i-1]; 42 k=a[i]; 43 } 44 } 45 } 46 } 47 printf("%d\n",b[n]); 48 } 49 }
标签:
原文地址:http://www.cnblogs.com/yexiaozi/p/5699171.html