这套题分别在总结3313~3321
A.
水
B.大模拟,敲了好长时间。。。
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; char str[35][1000] = { "111111MMM11111111MMMMMMMMMMM111111111MMMMMMMM1111MMMMMMMMMMM11111MMMMMMMMMMMM1111MMMMMMMMMMMMM11" ,"11111MM1MM1111111MM11111111MM111111MM1111111MM111MM111111111MM111MM11111111111111MM1111111111111" ,"1111MM111MM111111MM11111111MM11111MM111111111MM11MM1111111111MM11MM11111111111111MM1111111111111" ,"111MMMMMMMMM11111MMMMMMMMMMM111111MM1111111111111MM1111111111MM11MMMMMMMMMMMM1111MMMMMMMMMMMMM11" ,"11MM1111111MM1111MM11111111MM11111MM111111111MM11MM1111111111MM11MM11111111111111MM1111111111111" ,"1MMM11111111MM111MM11111111MM111111MM1111111MM111MM111111111MM111MM11111111111111MM1111111111111" ,"1MM1111111111MM11MMMMMMMMMMM111111111MMMMMMMM1111MMMMMMMMMMM11111MMMMMMMMMMMM1111MM1111111111111" ,"11111MMMMMMMM1111MM111111111MM1111111MMMMMM111111111MMMMMMMM111111MM111111MMM11111MM111111111111" ,"111MM1111111MM111MM111111111MM111111111MM11111111111111MM111111111MM11111MMM111111MM111111111111" ,"11MM111111111MM11MM111111111MM111111111MM11111111111111MM111111111MM111MMM11111111MM111111111111" ,"11MM1111111111111MMMMMMMMMMMMM111111111MM11111111111111MM111111111MMMMM11111111111MM111111111111" ,"11MM111111MMMMM11MM111111111MM111111111MM1111111111MM11MM111111111MM111MMM11111111MM111111111111" ,"111MM1111111MM111MM111111111MM111111111MM1111111111MMM1MM111111111MM11111MMM111111MM111111111111" ,"11111MMMMMMMMM111MM111111111MM1111111MMMMMM1111111111MMMM111111111MM111111MMMM1111MMMMMMMMMMMM11" ,"1MM1111111111MM11MMM111111111MM111111MMMMMM111111MMMMMMMMMMM111111111MMMMMM111111MMMMMMMMMMM1111" ,"1MMMM111111MMMM11MMMM11111111MM1111MMM1111MMM1111MM111111111MM11111MMM1111MMM1111MM111111111MM11" ,"1MM1MM1111MM1MM11MM1MM1111111MM111MMM111111MMM111MM1111111111MM111MMM111111MMM111MM1111111111MM1" ,"1MM11MMMMM111MM11MM11MM111111MM11MM1111111111MM11MM111111111MM111MM1111111111MM11MM111111111MM11" ,"1MM1111M11111MM11MM1111MM1111MM111MMM111111MMM111MMMMMMMMMMM111111MMM1MMMM1MMM111MMMMMMMMMMM1111" ,"1MM1111111111MM11MM111111MMM1MM1111MMM1111MMM1111MM1111111111111111MMM11MMMMM1111MM11111111MM111" ,"1MM1111111111MM11MM11111111MMMM111111MMMMMM111111MM1111111111111111111MMMM1MMMM11MM111111111MMM1" ,"1111MMMMMMMM111111MMMMMMMMMMMM111MM1111111111MM11MMMM111111MMMM11MM1111111111MM111MMM111111MMM11" ,"111MM1111111MM1111MMMMMMMMMMMM111MM1111111111MM111MMM111111MMM111MM1111111111MM1111MMM1111MMM111" ,"11MMM1111111MMM11111111MM11111111MM1111111111MM111MMM111111MMM1111MM111MM111MM111111MMM11MMM1111" ,"1111MMMMM11111111111111MM11111111MM1111111111MM1111MMM1111MMM11111MM111MM111MM11111111MMMM111111" ,"1MMM111MMMM111111111111MM11111111MMM11111111MMM11111MMM11MMM111111MM111MM111MM111111MMM11MMM1111" ,"111MMM11111MMM111111111MM11111111MMM11111111MMM111111MM11MM1111111MM1MM11MM1MM11111MMM1111MMM111" ,"11111MMMMMMM11111111111MM1111111111MMMMMMMMMM111111111MMMM111111111MMM1111MMM11111MMM111111MMM11" ,"11MMM111111MMM11111MMMMMMMMMM111" ,"111MMM1111MMM1111111111111MM1111" ,"1111MMM11MMM1111111111111MM11111" ,"111111MMMM11111111111111MM111111" ,"1111111MM1111111111111MM11111111" ,"1111111MM111111111111MM111111111" ,"1111111MM1111111111MMMMMMMMMMM11" }; int num[30]; //强联通有多少个节点 int weizhi[26][7*16][2]; //第i个字母dfs到的地k各节点与起点的差 int nn; int judge(int x, int y, int x1, int x2, int y1, int y2){ if(x1 <= x && x <= x2 && y1 <= y && y <= y2 && str[x][y] =='M')return 1; return 0; } int move[8][2] = {0, 1, 0, -1, 1, 0, 1, -1, 1, 1, -1, 0, -1, -1, -1, 1}; int vis[305][305], vis1[305][305]; int dfs(int x, int y, int sx, int sy, int x1, int x2, int y1, int y2){//printf("%d %d %d %d %d %d %d %d\n", x, y, sx, sy,x1,x2,y1,y2); if(vis[x][y])return 0; vis[x][y] = 1; weizhi[nn][num[nn]][0] = sx-x; weizhi[nn][num[nn]++][1] = sy-y; /*if(nn == 'u'-'a'){ printf("**%d %d %d %d\n", weizhi['u'-'a'][num[nn]-1][0], weizhi['u'-'a'][num[nn]-1][1], sx-x, sy-y); }*/ for(int i = 0; i < 8; i++){ if(judge(x+move[i][0], y+move[i][1],x1,x2, y1, y2)){//printf("**%d %d %d %d %d %d %d %d\n", x+move[i][0], y+move[i][1], sx, sy,x1,x2,y1,y2); dfs(x+move[i][0], y+move[i][1], sx, sy,x1,x2, y1, y2); } } } char str1[305][305]; int judge1(int x, int y, int n, int m){ if(0 <= x && x < n && 0 <= y && y < m && str1[x][y] == 'M') return 1; return 0; } int nnu, dp; void dfs1(int x, int y, int n, int m, int sx, int sy){//printf("%d %d %d %d\n", x, y, sx, sy); if(vis1[x][y])return; vis1[x][y] = 1; if(nnu < 7*17){ //printf("**%d %d ", weizhi['u'-'a'][nnu][0], weizhi['u'-'a'][nnu][1]); //printf("%d ", dp); int s= 0; int xx = sx - x, yy = sy - y; for(int i = 0; i < 26; i++){ if(weizhi[i][nnu][0] == xx && weizhi[i][nnu][1] == yy){ s |= (1<<i); } }//printf("--%d--", s); dp &= s; //printf("%d %d %d %d\n", sx-x,sy-y, dp, s); nnu++; }else dp = 0; for(int i = 0; i < 8; i++){ if(judge1(x+move[i][0], y+move[i][1], n, m)){ dfs1(x+move[i][0], y+move[i][1], n, m, sx, sy); } } } int ans[30]; int Ans(int n, int m){ memset(vis1, 0, sizeof(vis1));; for(int i = 0; i < n; i++){ for(int k = 0; k < m; k++){ if(vis1[i][k] || str1[i][k]!='M')continue; nnu = 0; dp = (1<<26)-1; dfs1(i, k, n, m, i, k);//printf("**%d\n", dp); for(int j = 0; j < 26; j++){ if(((1<<j) & dp) && nnu == num[j]){ ans[j] = 1; } } } } } char ss[305][305]; int main(){ for(int i =0; i < 35; i+= 7){ for(int k = 0; k < 96; k+=16){ int x1 = i,x2 = i+6, y1 = k, y2 = k+16; for(int ii = i; ii < i+7; ii++){ for(int kk = k; kk < k +16; kk++){ if(vis[ii][kk])continue; if(str[ii][kk] == 'M'){//printf("%d %d\n", ii, kk); dfs( ii, kk, ii, kk,x1,x2,y1,y2); } } } nn++; if(nn == 26)break; } } int n, m; while(scanf("%d%d", &n, &m)!=EOF){ memset(ans, 0, sizeof(ans)); for(int i = 0;i < n; i++){ scanf("%s", str1[i]); } //Ans(n, m); for(int u = 0; u < 4; u++){ Ans(n, m); for(int i = 0;i < m; i++){ for(int k = 0; k < n ;k++){ ss[i][k] = str1[n-1-k][i]; } }swap(n, m); for(int i =0 ; i <n;i++){ for(int k = 0; k < m ; k++){ str1[i][k] = ss[i][k]; } } } for(int i = 0;i < 26; i++){ if(ans[i])printf("%c", 'A'+i); }puts(""); } }