普及 最急救助 (红)
模拟
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (int x = l; x <= r; ++x)
#define fio(x, r, l) for (int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 998244353, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int Pow(int a, int b) {
int ans = 1;
for (; b; b >>= 1, mmod(a, a)) if (b & 1) mmod(ans, a);
return ans;
}
inline int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 2e2 + 3, maxm = 1e2 + 3;
char str[maxn], name[maxn];
int Max, tot;
char ans[maxn][maxn];
signed main() {
int n = read();
fop(i, 1, n) {
scanf("%s", name + 1);
scanf("%s", str + 1);
int res = 0;
int len = strlen(str + 1);
fop(i, 1, len - 2) if (str[i] == 's' && str[i + 1] == 'o' && str[i + 2] == 's') ++res;
if (res > Max) tot = 0, Max = res;
if (res == Max) memcpy(ans[++tot], name, sizeof name);
}
fop(i, 1, tot) printf("%s ", ans[i] + 1);
printf("\n%lld\n", Max);
}
普及 观星 (橙)
基础 BFS
联通块大小数组一定要记得开 maxn * maxn。。。又在这挂了
点击查看代码
#include <bits/stdc++.h>
#define ff fflush(stdout)
#define thank puts("I *** thank you ccf"), ff
#define bug(...) fprintf(stderr, __VA_ARGS__)
#define fop(x, l, r) for (int x = l; x <= r; ++x)
#define fio(x, r, l) for (int x = r; x >= l; --x)
#define edg(x, u) for (int x = head[u]; x; x = nxt[x])
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define mem(x) memset(x, 0, sizeof x)
const int mod = 998244353, inf = 0x3f3f3f3f3f3f3f3fll;
void ckmax(int &a, int b) { a = max(a, b); }
void ckmin(int &a, int b) { a = min(a, b); }
void amod(int &a, int b) { a += b; if (a >= mod) a -= mod; }
void mmod(int &a, int b) { a = 1ll * a * b % mod; }
void smod(int &a, int b) { a -= b; if (a < 0) a += mod; }
int amo(int a, int b) { int c = a + b; if (c >= mod) c -= mod; return c; }
int mmo(int a, int b) { return 1ll * a * b % mod; }
int smo(int a, int b) { int c = a - b; if (c < 0) c += mod; return c; }
int Pow(int a, int b) {
int ans = 1;
for (; b; b >>= 1, mmod(a, a)) if (b & 1) mmod(ans, a);
return ans;
}
inline int read() {
int x = 0; char c; bool f = 0;
while (!isdigit(c = getchar())) if (c == '-') f = 1;
do x = (x << 1) + (x << 3) + (c ^ 48); while (isdigit(c = getchar()));
return f ? -x : x;
}
const int maxn = 1.5e3 + 3, maxm = 1e2 + 3;
int n, m;
int mp[maxn][maxn];
bool Check(int x, int y) { return x > 0 && y > 0 && x <= n && y <= m && mp[x][y] == 3; }
const int dx[] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int dy[] = { 1, 0, -1, 1, -1, 1, 0, -1 };
bool vis[maxn][maxn];
int siz[maxn * maxn], tot;
int t[maxn * maxn];
void DFS(int x, int y) {
mp[x][y] = 1, ++siz[tot];
fop(i, 0, 7) if (Check(x + dx[i], y + dy[i])) DFS(x + dx[i], y + dy[i]);
}
char str[maxn];
signed main() {
n = read(), m = read();
fop(i, 1, n) {
scanf("%s", str + 1);
fop(j, 1, m) mp[i][j] = str[j] == '*' ? 3 : 2;
}
fop(i, 1, n) fop(j, 1, m) if (mp[i][j] == 3) ++tot, DFS(i, j);
fop(i, 1, tot) ++t[siz[i]];
int ans1 = 0, ans2 = 0;
fop(i, 1, n * n) if (t[i]) ++ans1, ckmax(ans2, t[i] * i);
printf("%lld %lld\n", ans1, ans2);
}