AOJ2243 Step Step Evolution

Step Step Evolution

Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown in the front screen.

左右交互に踏めなくなった回数を数える.最初に左足,右足の パターンのを取る. で場合分けをしたが, になっている箇所があることにずっと気づかずに時間を溶かした.気をつけたい.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool can(bool f, int cur, int to) {
  if(f) {
      if(cur % 3 == 1 && to % 3 != 1) return false;
      if(cur % 3 == 2 && to % 3 == 0) return false;
      return true;
  } else {
      if(cur % 3 == 0 && to % 3 != 0) return false;
      if(cur % 3 == 2 && to % 3 == 1) return false;
      return true;
  }
}

int main() {
  string s;
  while(cin >> s) {
      if(s == "#") break;

      vector<int> v(s.size());
      rep(i, s.size()) v[i] = s[i] - '0';

      int ans = INF, res = 0;
      int left = v[0], right = 0, ord = 0;

      REP(i, 1, v.size()) {
          if(ord & 1) {
              if(can(1, right, v[i])) {
                  left = v[i];
                  ord++;
              } else {
                  right = v[i];
                  res++;
              }
          } else {
              if(can(0, left, v[i])) {
                  right = v[i];
                  ord++;
              } else {
                  left = v[i];
                  res++;
              }
          }
      }

      ans = min(ans, res);

      res = 0;
      left = 0, right = v[0], ord = 1;
      REP(i, 1, v.size()) {
          if(ord & 1) {
              if(can(1, right, v[i])) {
                  left = v[i];
                  ord++;
              } else {
                  right = v[i];
                  res++;
              }
          } else {
              if(can(0, left, v[i])) {
                  right = v[i];
                  ord++;
              } else {
                  left = v[i];
                  res++;
              }
          }
      }

      ans = min(ans, res);
      cout << ans << endl;
  }
  return 0;
}
Mar 20th, 2016