标签:rip first string cas any \n play xpl case
Description
Input
Output
Sample Input
Sample Output
Hint
first sample can be explained as below.
题目意思:这是一个连连看游戏,只要矩阵内部有两个相同图案相邻或者外围(四条最外边)上只少有两个相同的图案,就可以进行一次消去,问能否进行一次消去。
解题思路:大致分为两种情况:1矩阵内部有相邻的图案,2矩阵外围上至少有两个相同的图案。直接暴力遍历这个矩阵即可。
1 #include<stdio.h> 2 #include<string.h> 3 int main() 4 { 5 int t,i,j,n,m,flag,count=1; 6 int a[32][32]; 7 scanf("%d",&t); 8 while(t--) 9 { 10 flag=0; 11 12 memset(a,0,sizeof(a)); 13 scanf("%d%d",&n,&m); 14 for(i=1; i<=n; i++) 15 { 16 for(j=1; j<=m; j++) 17 { 18 scanf("%d",&a[i][j]); 19 } 20 } 21 for(i=1; i<m; i++) 22 { 23 for(j=i+1; j<=m; j++) 24 { 25 if(a[1][i]==a[1][j]||a[n][i]==a[n][j]) 26 { 27 flag=1; 28 } 29 } 30 if(flag==1) 31 { 32 break; 33 } 34 } 35 for(i=1; i<n; i++) 36 { 37 for(j=i+1; j<=n; j++) 38 { 39 if(a[i][1]==a[j][1]||a[i][m]==a[j][m]) 40 { 41 flag=1; 42 } 43 } 44 if(flag==1) 45 { 46 break; 47 } 48 } 49 for(i=1; i<=n; i++) 50 { 51 for(j=1; j<=m; j++) 52 { 53 if(i!=n&&a[i][j]==a[i+1][j]) 54 { 55 flag=1; 56 } 57 if(j!=m&&a[i][j]==a[i][j+1]) 58 { 59 flag=1; 60 } 61 } 62 if(flag==1) 63 { 64 break; 65 } 66 } 67 if(flag==1) 68 { 69 printf("Case #%d: Yes\n",count); 70 count++; 71 } 72 else 73 { 74 printf("Case #%d: No\n",count); 75 count++; 76 } 77 } 78 return 0; 79 }
标签:rip first string cas any \n play xpl case
原文地址:https://www.cnblogs.com/wkfvawl/p/9049231.html