#define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> usingnamespace std; constint N = 1005; int n, m; int p[N][N]; int vis[N][N];
int dx[] = { 0,0,1,-1 }; int dy[] = { 1,-1,0,0 };
int ans = 1; // 记录答案
voiddfs(int x, int y){ for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (xx < 1 || xx > n || yy <1 || yy> n || vis[xx][yy] != 0 || p[xx][yy] == p[x][y]) continue; vis[xx][yy] = 1; ans++; dfs(xx, yy); } }
intmain(){ cin >> n >> m; string s; for (int i = 1; i <= n; i++) { cin >> s; for (int j = 1; j <= n; j++) { char a = s[j - 1]; if (a == '0') { p[i][j] = 0; } elseif (a == '1') p[i][j] = 1; else p[i][j] = 9; } } for (int i = 1; i <= m; i++) { int x, y; cin >> x >> y; memset(vis, 0, sizeof vis), ans = 1, vis[x][y] = 1; dfs(x, y); cout << ans << endl; } system("pause"); return0; }
voidunionn(int x, int y)//并 { int r1 = find(x), r2 = find(y); if (find(x) != find(y))h[find(x)] += h[find(y)], f[find(y)] = f[find(x)]; }
intdfs(int x, int y){ if (f[x * n + y] != -1) returnfind(x * n + y); f[x * n + y] = x * n + y, h[x * n + y] = 1;// 构造映射,且初始化 for (int i = 0; i < 4; i++) { int xx = x + dx[i], yy = y + dy[i]; if (xx >= 0 && xx < n && yy >= 0 && yy < n && s[xx][yy] != s[x][y]) unionn(x * n + y, dfs(xx, yy)); } returnfind(x * n + y); }
intmain(){ int t; cin >> n >> t; memset(f, -1, sizeof (4*n*n)); for (int i = 0; i < n; i++) { scanf("%s", s[i]); } int i, j; while (t--) { scanf("%d%d", &i, &j); cout << h[dfs(i - 1, j - 1)] << endl; } return0; }
priority_queue<int, vector<int>, less<int>> da; priority_queue<int, vector<int>, greater<int>> xiao;
int m,a;
intmain(){ cin >> m; for (int i = 1; i <= m; i++) { cin >> a; if (i == 1) { xiao.push(a); cout << xiao.top() << endl; } else { if (i % 2 ==0) { int c = xiao.top(); if (a <= c) { da.push(a); } else { xiao.pop(); xiao.push(a); da.push(c); } } else { int c = da.top(); if (a >= c) { xiao.push(a); } else { da.pop(); da.push(a); xiao.push(c); } cout << xiao.top() << endl; } } } }