牛客多校(2020第八場)G-Game SET
阿新 • • 發佈:2020-08-05
題意:輸入n種牌以及牌的屬性,任意選3張,這3張滿足4種屬性,要麼全相同,要麼全不同,“*”是萬能牌,可以變成你想要的任意的牌,輸出3張拍的序號。
題解:暴力列舉
1 //暴力 2 #include<iostream> 3 #include<cstring> 4 #include<algorithm> 5 #include<vector> 6 #include<string> 7 #include<unordered_map> 8 #include<set> 9 usingnamespace 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<n; 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<len; 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 }