A.水盐平衡
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; void solve() { int a, b, c, d; cin >> a >> b >> c >> d; if (a * d < c * b) cout << "Y\n"; else cout << "S\n"; } int main() { IO; int t; cin >> t; while (t--) { solve(); } return 0; }
B.水平考试
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; void solve() { string a, b; cin >> a >> b; for (auto& x : a) { if (!count(b.begin(), b.end(), x)) { cout << "0\n"; return ; } } cout << "10\n"; } int main() { IO; int t; cin >> t; while (t--) { solve(); } return 0; }
D
#include <bits/stdc++.h> #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const int N = 1005; char arr[N][N]; int n, m, cnt, maxx, maxy, minx, miny; int dirs[][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; bool isVild(int x, int y) { if (x >= 0 && x < n && y >= 0 && y < m && arr[x][y] == '.') { return true; } return false; } void dfs(int x, int y) { arr[x][y] = '*'; cnt ++; maxx = max(maxx, x), maxy = max(maxy, y); minx = min(minx, x), miny = min(miny, y); for (int i = 0; i < 4; i++) { int dx = dirs[i][0] + x; int dy = dirs[i][1] + y; if (isVild(dx, dy)) { dfs(dx, dy); } } } bool check(int maxx, int maxy, int minx, int miny, int cnt) { return (maxx - minx + 1) * (maxy - miny + 1) == cnt; } int main() { IO; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cin >> arr[i][j]; } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (arr[i][j] == '.') { cnt = 0, maxx = maxy = 0, minx = miny = N; dfs(i, j); if (check(maxx, maxy, minx, miny, cnt)) ans ++; } } } return cout << ans << '\n', 0; }
标签:maxx,maxy,miny,真小白,++,minx,牛客,int,86 From: https://www.cnblogs.com/youhualiuh/p/17976334