Coconuts hud5925 搜索+离散化
离散化
离散化判断联通块的个数还可以,但是这题竟然还让输出每个连通块的数量,除了签到题,其它题都太难了吧。
离散化墙的位置。
离散x坐标时,在离散x0 时,还要加入 x0 - 1该点也要进行离散化,才能确保两个不相邻的两点在离散化后仍然不相邻。
同时,每个点离散化后的坐标应该有一个权值表示空白快的宽度即可。
搜索
一块的面积即空白网格的数量。
广搜即可。
/*
hello world!
Just do it!
start time:2022-05-02 08:47:59.118827
*/
// #pragma GCC optimize (2)
// #pragma G++ optimize (2)
#include <bits/stdc++.h>
#define zero(x) memset(x, 0, sizeof(x));
#define one(x) memset(x, -1, sizeof(x));
#define m_INF(x) memset(x, 0x3f, sizeof(x));
#define m_inf(x) memset(x, 0x3f, sizeof(x));
#define m_f_INF(x) memset(x, -0x3f, sizeof(x));
#define m_f_inf(x) memset(x, -0x3f, sizeof(x));
#define all(x) x.begin(), x.end()
#define endl "\n"
#define fi first
#define se second
#define lbt(x) ((x)&(-x))
#define pb push_back
struct cmpl{ template <typename A, typename B> bool operator()(const A &a1, const B &b1) { return b1 < a1; } };
struct cmpg{ template <typename A, typename B> bool operator()(const A &a1, const B &b1) { return a1 < b1; } };
#define p_ql(x) priority_queue<x, vector<x>, cmpl>
#define p_qlp(x, y) priority_queue<pair<x, y>, vector<pair<x, y>>, cmpl>
#define p_qg(x) priority_queue<x, vector<x>, cmpg>
#define p_qgp(x, y) priority_queue<pair<x, y>, vector<pair<x, y>>, cmpg>
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
#define fo(i,from,to) for(int i=(from),ooo=(from)<(to)?1:-1,oooo=(to)+ooo;i!=oooo;i+=ooo)
#define fol(i,from,to) for(long long i=(from),ooo=(from)<(to)?1:-1,oooo=(to)+ooo;i!=oooo;i+=ooo)
#define foo(i,ooo) for(auto i=ooo.rbegin();i!=ooo.rend();++i)
#define foa(i,from,to) for(int i=(from),ooo=(to);i<=ooo;++i)
#define fos(i,from,to) for(int i=(from),ooo=(to);i>=ooo;--i)
using namespace std;
#ifndef LOCAL
# define dbg(...) ;
#endif
#define itn int
#define int long long
#ifdef int
#define inf (0x3f3f3f3f3f3f3f3f)
#else
#define inf (0x3f3f3f3f)
#endif
typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii;
const int dir[8][2]={{0,1},{1,0},{0,-1},{-1,0},{1,1},{1,-1},{-1,1},{-1,-1}}, INF = 0x3f3f3f3f, f_inf = -1044266559, f_INF = -1044266559;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int N = 1e6 + 10;
int n, m;
void init()
{
}
pii a[210];
int p[500][500], rr, cc;
void solve()
{
cin >> rr >> cc >> n;
vector<int> vx = {0, rr, rr + 1}, vy = {0, cc, cc + 1};
foa(i, 1, n) {
int x, y;
cin >> x >> y;
a[i] = {x, y};
vx.pb(x);
vx.pb(x - 1);
vy.pb(y);
vy.pb(y - 1);
}
sort(all(vx));
vx.erase(unique(all(vx)), vx.end());
sort(all(vy));
vy.erase(unique(all(vy)), vy.end());
zero(p);
map<int, int> mx, my;
int r = vx.size() - 1, c = vy.size() - 1;
a[++n] = {rr + 1, cc + 1};
foa(i, 1, n) {
int x = lower_bound(all(vx), a[i].fi) - vx.begin();
int y = lower_bound(all(vy), a[i].se) - vy.begin();
p[x][y] = 1;
mx[x] = 1;
if(x > 1) mx[x - 1] = vx[x] - vx[x - 2] - 1;
my[y] = 1;
if(y > 1) my[y - 1] = vy[y] - vy[y - 2] - 1;
}
// dbg(p, r, c, vx, mx, my)
vector<int> res;
foa(x, 1, r - 1) {
foa(y, 1, c - 1) {
if(p[x][y]) continue;
int num = 0;
queue<pii> q;
q.push({x, y});
p[x][y] = 1;
while(q.size()) {
auto t = q.front();
q.pop();
num += mx[t.fi] * my[t.se];
// dbg(t, mx[t.fi], my[t.se])
foa(i, 0, 3) {
int nx = t.fi + dir[i][0], ny = t.se + dir[i][1];
if(nx < 1 || nx >= r || ny < 1 || ny >= c || p[nx][ny]) continue;
q.push({nx, ny});
p[nx][ny] = 1;
}
}
res.pb(num);
}
}
sort(all(res));
cout << res.size() << endl;
foa(i, 0, res.size() - 1) cout << res[i] << " \n"[i == res.size() - 1];
// cout << endl;
}
signed main()
{
#ifdef LOCAL
freopen("read.in", "r", stdin);
freopen("write.out", "w", stdout);
#endif
std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
init();
int t = 0, num2 = 0;
// t = 1;
if (!t) cin >> t;
while (t--) {
cout<<"Case #"<<++num2<<":\n";
solve();
}
return 0;
int num1 = 0;
//while (scanf("%d", &n) !=-1 && n)
while (cin >> n && n) {
//cout<<"Case "<<++num1<<": ";
solve();
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」