# Codeforces 698A Vacations

Source: Internet
Author: User

Topic Link: Http://codeforces.com/problemset/problem/698/A topic to the effect:

Ah Q has a N-day holiday, there are three kinds of holidays to arrange rest, fitness, competition. There are three different options per day:

0 Gym doesn't open, no games.

1 Gym doesn't open, there's a game.

2 Gym open, no competition.

The 3 gym is open for games.

Please give AH Q reasonable arrangements for his holiday "Ah Q can not be attached to two days of fitness or a two-day match", so that a Q of the minimum number of rest days.

Problem Solving Ideas:

Ans=n, up to rest ans days

The first day was 3 a[0]=0,ans--;

As long as it is a[0]>0, then ans--;

Starting from the next day in the following day:

If the day is 1 then judge whether it was 1 days before

1: Make the current a[i]=0, rest today.

！ 1: Must exercise yesterday, ans--。

If the day is 2 then judge whether it was 2 days before

2: Make the current a[i]=0, rest today.

！ 2: Must match yesterday, ans--。

If the day is 3, make the key judgment.

If yesterday for 1 then today a[i]=2 ans--;

If yesterday for 2 then today A[i]=1 ans--;

If yesterday for 0 then today arbitrarily do a[i]=0 ans--; Focus

0 Do not judge anyway is rest ans remains unchanged.

Example:

7

1331123

1 ans--; 3 ans--, a[i]=2; 3 the day before 2 ans--, a[i]=1; 1 the day before 1 rest a[i]=0; 1 the day before was 0 ans--; 2 the day before was 1 ans--; 3 the day before was 2,a[i]=1 ans--;

Results: Ans=1.

AC Code:

`1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5     intN;6      while(~SCANF ("%d",&N))7     {8         intans=n,flag=0, a[n+2];9          for(intI=0; i<n; i++)Tenscanf"%d",&a[i]); One         if(a[0]>0) ans--; A         if(a[0]==3) a[0]=0; -          for(intI=1; i<n; i++) -         { the             Switch(A[i]) -             { -              Case 1: -                 if(a[i-1]!=1) ans--; +                 Elsea[i]=0; -                  Break; +              Case 2: A                 if(a[i-1]!=2) ans--; at                 Elsea[i]=0; -                  Break; -              Case 3: -                 if(a[i-1]==1) a[i]=2, ans--; -                 Else if(a[i-1]==2) a[i]=1, ans--; -                 Else if(a[i-1]==0) a[i]=0, ans--; in                  Break; -             } to         } +cout<<ans<<Endl; -     } the     return 0; *}`

Codeforces 698A Vacations

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.