牛客多校(2020第八场)G-Game SET

题意:输入n种牌以及牌的属性,任意选3张,这3张满足4种属性,要么全相同,要么全不同,“*”是万能牌,可以变成你想要的任意的牌,输出3张拍的序号。

题解:暴力枚举

更新一种更简洁明了的代码

 1 //暴力
 2 #include
 3 #include
 4 #include
 5 #include
 6 #include<string>
 7 #include
 8 #include<set>
 9 using namespace std;
10 
11 const int N = 260;
12 vector <string> vet;
13 unordered_map<string, string> ma, mb, mc, md, mp;
14 
15 void init() {
16     mp["one"]="1";
17     mp["two"]="2";
18     mp["three"]="3";
19     mp["diamond"]="1";
20     mp["squiggle"]="2";
21     mp["oval"]="3";
22     mp["solid"]="1";
23     mp["striped"]="2";
24     mp["open"]="3";
25     mp["red"]="1";
26     mp["green"]="2";
27     mp["purple"]="3";
28     mp["*"]="0";
29 }
30 
31 
32 inline string read() {
33     string p;
34     p = "";
35     char ch = getchar();
36     while ((ch < 'a' || ch > 'z') && ch != '*')  {
37         ch = getchar();
38     }
39     while ((ch >= 'a' && ch <= 'z') || ch == '*') {
40         p += ch;
41         ch = getchar();
42     }
43     return p;
44 }
45 
46 bool worng(char fir, char sec, char thi) {
47     if (fir == '0' || sec == '0' || thi == '0')   return 0; //只要有一个为万能*则符合
48     else {
49         if (fir == sec && sec == thi)   return 0;
50         if (fir != sec && fir != thi && sec != thi) return 0;
51     }
52 
53     return 1;
54 }
55 
56 bool judge(int i, int j, int k) {
57     string fri = vet[i], sec = vet[j], thr = vet[k];
58     bool one = worng(fri[0], sec[0], thr[0]);
59     bool two = worng(fri[1], sec[1], thr[1]);
60     bool three = worng(fri[2], sec[2], thr[2]);
61     bool four = worng(fri[3], sec[3], thr[3]);
62     if (one || two || three || four)    return false;
63     return true;
64 }
65 
66 void solve(int n, int t) {
67     for (int i = 0; i < n - 2; i++) {
68         for (int j = i+1; j < n - 1; j++) {
69             for (int k = j+1; k < n; k++) {
70                 if (judge(i, j, k)) {
71                     printf("Case #%d: %d %d %d\n", t, i+1, j+1, k+1);
72                     return;
73                 }
74             }
75         }
76     }
77     printf("Case #%d: -1\n", t);
78 }
79 
80 int main() {
81     int T;
82     cin >> T;
83     init();
84     for (int cas = 1; cas <= T; cas++) {
85         int n;
86         vet.clear();
87         cin >> n;
88         for (int i = 0; i < n; i++) {
89             string one = read();
90             string two = read();
91             string three = read();
92             string four = read();
93             vet.push_back({mp[one]+mp[two]+mp[three]+mp[four]});
94         }
95         solve(n, cas);
96     }
97     return 0;
98 }

 

分割线——————————————————————

 1 //暴力
 2 #include
 3 #include
 4 #include
 5 #include
 6 #include<string>
 7 #include
 8 #include<set>
 9 using namespace std;
10 
11 const int N = 260;
12 
13 char s[N][50];
14 string ss[N][6];
15 
16 
17 bool worng(string fir, string sec, string thi) {
18     if (fir == "*" || sec == "*" || thi == "*")   return 0; //只要有一个为万能*则符合
19     else {
20         if (fir == sec && sec == thi)   return 0;
21         if (fir != sec && fir != thi && sec != thi) return 0;
22     }
23     return 1;
24 }
25 
26 bool judge(int id1, int id2, int id3) {
27     bool one = worng(ss[id1][1],ss[id2][1],ss[id3][1]);
28     bool two = worng(ss[id1][2],ss[id2][2],ss[id3][2]);
29     bool three = worng(ss[id1][3],ss[id2][3],ss[id3][3]);
30     bool four = worng(ss[id1][4],ss[id2][4],ss[id3][4]);
31     if (one || two || three || four)    return false;
32     return true;
33 }
34 
35 void solve(int n, int t) {
36     for (int i = 0; i < n - 2; i++) {
37         for (int j = i+1; j < n - 1; j++) {
38             for (int k = j+1; k < n; k++) {
39                 if (judge(i, j, k)) {
40                     printf("Case #%d: %d %d %d\n", t, i+1, j+1, k+1);
41                     return;
42                 }
43             }
44         }
45     }
46     printf("Case #%d: -1\n", t);
47 }
48 
49 int main() {
50     int T;
51     cin >> T;
52     for (int cas = 1; cas <= T; cas++) {
53         int n;
54         cin >> n;
55         for (int i=0; i){
56             scanf ("%s",s[i]);
57             int len=strlen(s[i]);
58             int cnt=1;
59             ss[i][1]=ss[i][2]=ss[i][3]=ss[i][4]="";
60             for (int j=0; j){
61                 if (s[i][j]==']') {cnt++; continue;}
62                 else if (s[i][j]=='[') continue;
63                 ss[i][cnt]+=s[i][j];
64             }
65         }
66         solve(n, cas);
67     }
68     return 0;
69 }

 

你可能感兴趣的:(牛客多校(2020第八场)G-Game SET)