【Codeforces】[698A]Vacations

Problem Description

Loading...

Problem Analysis

Note that the question asks for the minimum number of rest days
so we need to keep the number of days with $a[i]==0$ as small as possible

Scan from front to back
if $a[i]==3$
then if $a[i-1]==1$, set $a[i]=2$
if $a[i-1]==2$, set $a[i]=1$

If a 3 appears at the very start of the loop, it needs no consideration
because no matter how many 3s there are, they can all be combined into busy days
with no effect on the answer

If $a[i]==a[i-1]$
then update $a[i]$ to 0

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
int a[120];
int main() {
    int n;
    while(scanf("%d",&n)!=EOF) {
        for(int i=0; i<n; i++) {
            scanf("%d",&a[i]);
            if(i>0&&a[i]==3&&(a[i-1]==1||a[i-1]==2))
                a[i]-=a[i-1];
            else if(i>0&&a[i]!=3&&a[i]==a[i-1])
                a[i]=0;
        }
        int cnt=0;
        for(int i=0; i<n; i++)
            if(a[i]==0)
                cnt++;
        printf("%d\n",cnt);
    }
    return 0;
}

Loading...