Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c59b10a

Browse files
Merge pull request #586 from kchung1995/weekly
Weekly
2 parents 7a294b6 + 7496fc2 commit c59b10a

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include <iostream>
2+
#include <vector>
3+
#include <set>
4+
using namespace std;
5+
#define MAX_N 10
6+
#define MAX_P 20
7+
8+
int n, k;
9+
int a[MAX_N][MAX_N];
10+
vector<vector<int> > will_play;
11+
int kyunghee[MAX_P];
12+
int minho[MAX_P];
13+
bool can_win = false;
14+
15+
void dfs(set<int> played, vector<int> score, int i, int j, vector<int> others) {
16+
if (can_win) return;
17+
for (int s = 0; s < score.size(); s++) {
18+
if (score[s] == k) {
19+
//지우가 가장 먼저 k점을 달성했다면
20+
if (s == 0) can_win = true;
21+
return;
22+
}
23+
}
24+
if (i > j) swap(i, j);
25+
26+
//경희와 민호가 승부하는 경우
27+
if (i == 1 && j == 2) {
28+
int kyunghee_play = will_play[1][others[1]], minho_play = will_play[2][others[2]];
29+
//경희(1)가 이기는 경우
30+
others[i]++; others[j]++;
31+
if (a[kyunghee_play][minho_play] == 2) {
32+
score[i]++;
33+
dfs(played, score, 0, 1, others);
34+
}
35+
//비기거나 민호(2)가 이기는 경우
36+
else {
37+
score[j]++;
38+
dfs(played, score, 0, 2, others);
39+
}
40+
return;
41+
}
42+
//지우가 승부하는 경우
43+
else {
44+
bool not_used_exists = false;
45+
for (int s = 1; s <= n; s++) {
46+
//이미 냈던 손동작은 다시 낼 수 없다.
47+
if (played.find(s) != played.end()) continue;
48+
//지우가 이기는 경우
49+
not_used_exists = true;
50+
if (a[s][will_play[j][others[j]]] == 2) {
51+
played.insert(s);
52+
score[0]++;
53+
others[j]++;
54+
if (j == 2) {
55+
dfs(played, score, 0, 1, others);
56+
}
57+
else if (j == 1) {
58+
dfs(played, score, 0, 2, others);
59+
}
60+
played.erase(s);
61+
score[0]--;
62+
others[j]--;
63+
}
64+
//지우가 비기거나 지는 경우
65+
else {
66+
played.insert(s);
67+
score[j]++;
68+
others[j]++;
69+
dfs(played, score, 1, 2, others);
70+
played.erase(s);
71+
score[j]--;
72+
others[j]--;
73+
}
74+
}
75+
if (!not_used_exists) return;
76+
}
77+
}
78+
79+
int main() {
80+
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
81+
//손동작의 종류 n, 우승을 위해 필요한 승수 k
82+
cin >> n >> k;
83+
//상성; A(i,j)가 2: i번 손동작이 j번 손동작을 이긴다.
84+
//1: i번 손동작이 j번 손동작과 비긴다.
85+
//0: i번 손동작이 j번 손동작에게 진다.
86+
for (int i = 1; i <= n; i++) {
87+
for (int j = 1; j <= n; j++) {
88+
cin >> a[i][j];
89+
}
90+
}
91+
//예외 처리
92+
if (n < k) {
93+
cout << 0;
94+
return 0;
95+
}
96+
//경희와 민호가 앞으로 20경기에서 낼 손동작
97+
vector<int> temp; temp.clear();
98+
99+
will_play.push_back(temp);
100+
temp.clear();
101+
for (int i = 0; i < MAX_P; i++) {
102+
int input; cin >> input; temp.push_back(input);
103+
}
104+
will_play.push_back(temp);
105+
temp.clear();
106+
for (int i = 0; i < MAX_P; i++) {
107+
int input; cin >> input; temp.push_back(input);
108+
}
109+
will_play.push_back(temp);
110+
111+
set<int> played;
112+
vector<int> score(3);
113+
vector<int> played_index(3);
114+
played_index[1] = 1;
115+
//지우, 경희, 민호
116+
for (int i = 1; i <= n; i++) {
117+
//지우가 이기는 경우
118+
if (a[i][will_play[1][0]] == 2) {
119+
played.insert(i);
120+
score[0]++;
121+
dfs(played, score, 0, 2, played_index);
122+
played.erase(i);
123+
score[0]--;
124+
}
125+
//비기는 경우 또는 지는 경우
126+
else {
127+
played.insert(i);
128+
score[1]++;
129+
dfs(played, score, 1, 2, played_index);
130+
played.erase(i);
131+
score[1]--;
132+
}
133+
}
134+
135+
if (can_win) cout << 1;
136+
else cout << 0;
137+
return 0;
138+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /