#include<iostream> #include<stdio.h> #include<math.h> #include<string.h> using namespace std; int snum,n,m,sum,flag; int map[35][35]; int hum[35][35]; char st[500]; int c,mmax; int num[30],tt[30]; int so[30]; int v[30]; int judge() { int i; for(i=1;i<=mmax;i++) { if(v[i] ==0) return 0; } return 1; } void dfs(int x) { if(flag) return; if(judge()==1) { flag=1; return ; } int i,j,k; int tmp; tmp=so[x] ; memset(num,0,sizeof(num)); for(j=1;j<=mmax;j++) { if(hum[x] [j] >0&&v[j] ==0) { for(k=1;k<=mmax;k++) { if(hum[j] [k] >0&&v[k] ==0) num[j] ++; } tmp+=(so[j] /(num[j] +1)); } } // cout<<"tem=="<<tmp<<" "<<snum<<endl; if(tmp<snum) { // cout<<"1"<<endl; v[x] =1; for(j=1;j<=mmax;j++) { tt[j] =so[j] ; // cout<<"hun[1][1]="<<hum[x][j]<<endl; // cout<<"v[1]="<<v[j]<<endl; if(hum[x] [j] >0&&v[j] ==0) { so[j] -=(so[j] /(num[j] +1)); } } // cout<<"2"<<endl; for(i=1;i<=mmax;i++) { // if(i==x)dfs(i); // else{ if(v[i] ==0) dfs(i); flag=judge(); //if(flag)return; // cout<<"try"<<endl; // cout<<"try2"<<endl; // } } // if(!flag){ v[x] =0; // cout<<"try3"<<endl; for(j=1;j<=mmax;j++) { // cout<<"try4"<<endl; if(hum[x] [j] >0&&v[j] ==0) { so[j] +=(tt[j] /(num[j] +1)); } } // cout<<"try5"<<endl; // } } // cout<<"try6"<<endl; return; } int main() { int i,j,t; scanf("%d",&t); while(t--) { cin>>n>>m; mmax=0; memset(hum,0,sizeof(hum)); for(i=1;i<=n;i++) { scanf("%s",st); for(j=0;j<m;j++) { map[i] [j+1]=st[j] -'A'+1; c=map[i] [j+1]; if(c>mmax) mmax=c; } } for(i=1;i<=mmax;i++) scanf("%d",&so[i]); scanf("%d",&snum); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { if(i+1<=n&&map[i] [j] !=map[i+1][j] ) { hum[map[i] [j] ][map[i+1][j] ]=hum[map[i+1][j] ][map[i] [j] ]=1; } if(j+1<=n&&map[i] [j] !=map[i] [j+1]) { hum[map[i] [j] ][map[i] [j+1]]=hum[map[i] [j+1]][map[i] [j] ]=1; } if(i-1>0&&map[i] [j] !=map[i-1][j] ) { hum[map[i] [j] ][map[i-1][j] ]=hum[map[i-1][j] ][map[i] [j] ]=1; } if(j-1>0&&map[i] [j] !=map[i] [j-1]) { hum[map[i] [j] ][map[i] [j-1]]=hum[map[i] [j-1]][map[i] [j] ]=1; } } } flag=0; // cout<<"1hhe"<<endl; for(i=1;i<=mmax;i++) { if(flag==1) break; dfs(i); } // cout<<"hhe"<<endl; if(flag) { printf("Saruman "); } else printf("Human "); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。