- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <string.h>
- typedef struct land
- {
- int up;
- int down;
- int left;
- int right;
- }lands;
- int max(int i,int m,int j ,int b[][50])
- {
- int sss;
- int q,p;
-
- sss=0;
- for(q=0;q<=i-1;q++)
- for(p=0;p<m;p++)
- {
-
- if(b[q][p]>=sss)
- {
- sss=b[q][p];
-
- }
- }
- for(p=0;p<=j;p++)
- {
- if(b[i][p]>=sss)
- {
- sss=b[i][p];
- }
-
- }
- return sss;
- }
- void main()
- {
- lands lan[11]={{1,0,1,0},{1,0,0,1},{0,1,1,0},{0,1,0,1},{1,1,0,0},{0,0,1,1},{1,0,1,1},{1,1,1,0},{0,1,1,1},{1,1,0,1},{1,1,1,1}};
-
- int num,n,m,i,j,k,p;
- char c[100][100],c1;
- while(1)
- {
- lands a[50][50]={0,0,0,0};
- int b[50][50]={0};
- scanf("%d %d",&n,&m);
- num=0;
- if(n<0||m<0)
- break;
- for(i=0;i<n;i++)
- { scanf("%s",c[i]);
- k=strlen(c[i]);
-
- for(j=0;j<k;j++)
- {
-
- switch(c[i][j])
- {
- case 'A': a[i][j]=lan[0];break;
- case 'B': a[i][j]=lan[1];break;
- case 'C': a[i][j]=lan[2];break;
- case 'D': a[i][j]=lan[3];break;
- case 'E': a[i][j]=lan[4];break;
- case 'F': a[i][j]=lan[5];break;
- case 'G': a[i][j]=lan[6];break;
- case 'H': a[i][j]=lan[7];break;
- case 'I': a[i][j]=lan[8];break;
- case 'J': a[i][j]=lan[9];break;
- case 'K': a[i][j]=lan[10];break;
-
- }
-
-
- }
- }
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- {
- if(i==0&&j==0)
- {
- b[i][j]=1;
-
- }
- else if(j==0&&i!=0)
- {
- if(a[i][j].up==1&&a[i-1][j].down==1)
- b[i][j]=b[i-1][j];
- else
- {
- b[i][j]=max( i, m, j,b)+1;
- }
-
- }
- else if(i==0&&j!=0)
- {
- if(a[i][j].left==1&&a[i][j-1].right==1)
- b[i][j]=b[i][j-1];
- else
-
- b[i][j]=max(i,m,j,b)+1;
-
- }
-
- else if(a[i][j].up==1&&a[i-1][j].down==1)
- {
- b[i][j]=b[i-1][j];
- if(a[i][j].left==1&&a[i][j-1].right==1)
- {
- if(b[i][j-1]>b[i][j])
- {
-
- for(k=0;k<=i-1;k++)
- {
- for(p=0;p<m;p++)
- {
- if(b[k][p]==b[i][j-1])
- b[k][p]=b[i][j];
-
- }
- }
- for(k=0;k<j-1;k++)
- if(b[i][k]==b[i][j-1])
- b[i][k]=b[i][j];
- }
- if(b[i][j-1]<b[i][j])
- {
- for(k=0;k<=i-1;k++)
- {
- for(p=0;p<m;p++)
- {
- if(b[k][p]==b[i][j])
- b[k][p]=b[i][j-1];
-
- }
- }
- for(k=0;k<j-1;k++)
- if(b[i][k]==b[i][j])
- b[i][k]=b[i][j-1];
-
- }
-
- b[i][j]=b[i][j]>b[i][j-1]?b[i][j-1]:b[i][j];
- b[i][j-1]=b[i][j];
- }
-
- }
- else if(a[i][j].left==1&&a[i][j-1].right==1)
- b[i][j]=b[i][j-1];
- else
- {
-
- b[i][j]=max(i,m,j,b)+1;
- }
-
- }
-
- int num=0;
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- {
-
- if(b[i][j]>=num)
- {
- num=b[i][j];
-
- }
- }
- printf("%d\n",num);
-
- }
-
- }
复制代码 |
|