第一题,直接模拟,看看是不是能胡特殊类型的牌!
代码:
#include<bits/stdc++.h> using namespace std; int main(void) { #ifndef ONLINE_JUDGE ifstream cin("in.txt"); #endif //faster_cin_cout; int T; cin >> T; while(T--) { string s[7]; int w = 0, b = 0, t = 0; for(int i = 0; i < 7; ++i) cin >> s[i]; for(int i = 0; i < 7; ++i) { if(s[i][1] == 'W') ++w; if(s[i][1] == 'B') ++b; if(s[i][1] == 'T') ++t; } if(w < 1 || b < 1 || t < 1 || w > 3 || b > 3 || t > 3) { cout << "NO" << endl; } else { cout << "YES" << endl; } } return 0; }
第二题,十字斩,直接模拟,没啥好说的!
代码:
#include<bits/stdc++.h> using namespace std; int main(void) { #ifndef ONLINE_JUDGE //ifstream cin("in.txt"); #endif int n; while(cin >> n) { vector<int> row(n, 0); vector<int> col(n, 0); vector<vector<int>> a(n, vector<int>(n, 0)); for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { scanf("%d", &a[i][j]); row[i] += a[i][j]; col[j] += a[i][j]; } } for(; n >= 1; n--) { if(n == 1) {printf("%d %d\n", 1, 1); break;} int r = -1, c = -1, s = -1; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(row[i] + col[j] - a[i][j] > s) { s = row[i] + col[j] - a[i][j]; r = i; c = j; } } } printf("%d %d\n", r+1, c+1); for(int j = 0; j < n; ++j) col[j] -= a[r][j]; for(int i = 0; i < n; ++i) row[i] -= a[i][c]; row.erase(row.begin() + r); col.erase(col.begin() + c); for(int i = 0; i < n; ++i) a[i].erase(a[i].begin() + c); a.erase(a.begin() + r); } } return 0; }
全部评论
(0) 回帖