标签:otto connect pix The com blank amp msu script
#include<cstdio> #include<iostream> using namespace std; const int N=1010; int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; char girl[]="girl"; char cat[]="cat"; char map[N][N]; int n,m,sumg,sumc; void dfsgirl(int i,int j,int cnt) { if(i<0||j<0||i>=n||j>=m) return; else{ if(map[i][j]==girl[cnt]){ if(cnt==3){ sumg++; return; } dfsgirl(i-1,j,cnt+1); dfsgirl(i,j-1,cnt+1); dfsgirl(i+1,j,cnt+1); dfsgirl(i,j+1,cnt+1); } } return; } void dfscat(int i,int j,int cnt) { if(i<0||j<0||i>=n||j>=m) return; else{ if(map[i][j]==cat[cnt]){ if(cnt==2){ sumc++; return; } dfscat(i-1,j,cnt+1); dfscat(i,j-1,cnt+1); dfscat(i+1,j,cnt+1); dfscat(i,j+1,cnt+1); } } return; } int main() { int t;scanf("%d",&t); while(t--){ sumg=0,sumc=0; scanf("%d%d",&n,&m); for(int i=0;i<n;i++){ scanf("%s",map[i]); } for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(map[i][j]==‘g‘){ dfsgirl(i,j,0); } if(map[i][j]==‘c‘){ dfscat(i,j,0); } } } printf("%d %d\n",sumg,sumc); } return 0; }
标签:otto connect pix The com blank amp msu script
原文地址:https://www.cnblogs.com/LJHAHA/p/10579050.html