Codeforces Round #102 (Div. 2) ——A. Help Vasilisa the Wise 2
呃。。。暴力水题,不解释。
View Code
1 #include<iostream>
2 #include<cstdio>
3 using namespace std;
4
5 bool vis[10];
6 bool law(int x)
7 {
8 return x<=9 && x>=1 && !vis[x];
9 }
10
11
12 int main()
13 {
14 for (int i(1); i<=9; ++i)vis[i] = false;
15 int c1,c2,r1,r2,d1,d2;
16 scanf("%d%d%d%d%d%d",&r1,&r2,&c1,&c2,&d1,&d2);
17 int a11,a12,a21,a22;
18 bool flag = true;
19 for (int i(1); i<=9; ++i) {
20 a11 = i;
21 vis[i] = true;
22 if (law(a12 = r1 - a11)) {
23 vis[a12] = true;
24 if (c1 - a11 == d2 - a12) {
25 if (law(a21 = c1 - a11)) {
26 vis[a21] = true;
27 if (c2 - a12 == r2 - a21 && r2 - a21 == d1 - a11) {
28 if (law(a22 = c2 - a12)) {
29 cout<<a11<<" "<<a12<<endl<<a21<<" "<<a22<<endl;
30 flag = false;
31 break;
32 }
33 }
34 vis[a21] = false;
35 }
36 }
37 vis[a12] = false;
38 }
39 vis[a11] = false;
40 }
41 if (flag)cout<<-1<<endl;
42 return 0;
43 }