这个世界上怎么会有这么多恶心人的搜索啊
做法...
找联通块,找完之后尝试赋颜色
判重很玄学,算联通块上点的两两距离,求和。如果和一样,那么图形一定一样
然后就苦逼搜索就行了
1.0h
#include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<cmath> #include<iostream> #include<map> using namespace std; #define O(x) cout << #x << " " << x << endl; #define O_(x) cout << #x << " " << x << " "; #define B cout << "breakpoint" << endl; #define clr(a) memset(a,0,sizeof(a)); #define pii pair<int,int> #define mp make_pair typedef double db; typedef long long ll; inline int read() { int ans = 0,op = 1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') op = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { (ans *= 10) += ch - '0'; ch = getchar(); } return ans * op; } const int maxn = 505; const db eps = 0.00000001; int w,h; int g[maxn][maxn]; int mark[maxn][maxn]; int dx[maxn][maxn],dy[maxn][maxn],n2,n1; db dist[maxn]; int ch = 0; int c[maxn]; db calc(int x1,int y1,int x2,int y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int judge(int k) { for(int i = 1;i <= n2;i++) for(int j = 1;j <= n2;j++) dist[k] += calc(dx[n1][i],dy[n1][i],dx[n1][j],dy[n1][j]); for(int i = 1;i < n1;i++) if(fabs(dist[i] - dist[k]) <= eps) return i; return 0; } void dfs(int x,int y) { for(int i = -1;i <= 1;i++) for(int j = -1;j <= 1;j++) { int nx = x + i,ny = y + j; if(nx < 1 || nx > w || ny < 1 || ny > h || mark[nx][ny] || !g[nx][ny]) continue; mark[nx][ny] = ch; dx[n1][++n2] = nx,dy[n1][n2] = ny; dfs(nx,ny); } } int main() { h = read(),w = read(); for(int i = 1;i <= w;i++) for(int j = 1;j <= h;j++) { char cha = getchar(); while(cha != '0' && cha != '1') cha = getchar(); g[i][j] = cha - '0'; } for(int i = 1;i <= w;i++) for(int j = 1;j <= h;j++) { if(!mark[i][j] && g[i][j]) { ch++; n2 = 1,n1++; mark[i][j] = ch; dx[n1][n2] = i,dy[n1][n2] = j; c[n1] = ch; dfs(i,j); int k = judge(n1); if(k) { ch--; for(int i = 1;i <= n2;i++) mark[dx[n1][i]][dy[n1][i]] = c[k]; } } } for(int i = 1;i <= w;i++) { for(int j = 1;j <= h;j++) mark[i][j] > 0 ? printf("%c",mark[i][j] + 'a' - 1) : printf("0"); printf(" "); } }