Algoogle

Algorithm for Programming Contest

AOJ 2245 Dice Room

Category: AOJ Tag: implementation

Dice Room

問題概要


解法


出入口の組み合わせは高々12通りなので手数を手元で全部書き出しておく.
あとは入力のなかで条件を満たす最小のものをだす. 糞コード

コード


(2245.cpp) download
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
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<a;i++)
using namespace std;
const int INF = 1e9;
string dice[6][3];

int main()
{
    while(1){
        cin >> dice[0][0];
        if(dice[0][0] == "#") break;
        cin >> dice[0][1] >> dice[0][2];
        rep(i,5)rep(j,3) cin >> dice[i+1][j];
        int ans = INF;
        bool exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[0][2][i] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[2][2][i] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 0);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[0][0][i] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[2][0][i] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 2);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[0][i][0] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[2][i][2] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 1);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[0][i][2] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[2][i][0] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 1);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[1][i][0] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[3][i][2] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 2);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[1][i][2] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[3][i][0] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 2);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[1][0][i] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[3][0][i] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 3);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[1][2][i] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[3][2][i] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 3);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[4][2][i] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[5][0][i] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 1);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[4][0][i] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[5][2][i] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 1);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[4][i][0] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[5][i][0] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 2);

        exist1 = 0, exist2 = 0;
        rep(i,3)if(dice[4][i][2] == '*'){ exist1 = 1; break;}
        rep(i,3)if(dice[5][i][2] == '*'){ exist2 = 1; break;}
        if(exist1 && exist2) ans = min(ans, 2);
        cout << ans << endl;
    }
    return 0;
}

Comments