The Fourth Dimension Space

枯叶北风寒,忽然年以残,念往昔,语默心酸。二十光阴无一物,韶光贱,寐难安; 不畏形影单,道途阻且慢,哪曲折,如渡飞湍。斩浪劈波酬壮志,同把酒,共言欢! -如梦令

浙大校赛 B

首先声明 这个代码是错的。。。

#include<iostream>
#include
<algorithm>
#include
<cstdio>
using namespace std;


int dp[100];
int n,m;
int dir[8][2]={{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{1,-1},{-1,1},{1,1}};

char s[1000][1000];

bool god(int x,int y)
{

    
if(x>=0&&x<n&&y>=0&&y<m)
        
return true;
    
else
        
return false;
}


void input()
{

    
int i;
    
int j;
    
for(i=0;i<n;i++)
        scanf(
"%s",s[i]);

}


int v[1000][1000];
int cnt;
void dfs(int x,int y)
{
    v[x][y]
=1;
    cnt
++;
    
int i;
    
//int nx;
    
//int ny;
    for(i=0;i<8;i++)
    
{
        
int nx=x+dir[i][0];
        
int ny=y+dir[i][1];
        
if(god(nx,ny)&&s[nx][ny]=='M'&&v[nx][ny]==0)
            dfs(nx,ny);
    }

}



int main()
{
    
int mx;
    
int my;
    
int i,j;
    
while(scanf("%d%d",&n,&m)!=EOF)
    
{
        memset(v,
0,sizeof(v));
        memset(dp,
0,sizeof(dp));
        input();
        
for(i=0;i<n;i++)
        
{

            
for(j=0;j<m;j++)
            
{
                cnt
=0;
                
if(s[i][j]=='M'&&v[i][j]==0)
                
{
                    mx
=i;
                    my
=j;
                    dfs(i,j);
                    
if(cnt==22)
                        dp[
'I'-'A']=1;
                    
else if(cnt==24)
                        dp[
'L'-'A']=1;
                    
else if(cnt==27)
                        dp[
'J'-'A']=1;
                    
else if(cnt==28)
                        dp[
'Y'-'A']=1;
                    
else if(cnt==31)
                        dp[
'Z'-'A']=1;
                    
else if(cnt==33)
                        dp[
'A'-'A']=1;
                    
else if(cnt==37)
                        dp[
'H'-'A']=1;
                    
else if(cnt==44)
                        dp[
'E'-'A']=1;
                    
else if(cnt==48)
                        dp[
'Q'-'A']=1;
                    
else if(cnt==49)
                        dp[
'B'-'A']=1;
                    
else if(cnt==34)
                    
{
                        
if(s[i+1][j+1]=='M')
                            dp[
'T'-'A']=1;
                        
else
                            dp[
'C'-'A']=1;
                    }

                    
else if(cnt==36)
                    
{
                        
if(s[i+6][j]=='1')
                            dp[
'K'-'A']=1;//倒K
                        else if(s[i+1][j+8]=='M')
                            dp[
'K'-'A']=1;
                        
else 
                            dp[
'F'-'A']=1


                    }

                    
else if(cnt==38)
                    
{
                        
if(s[i+2][j+2]=='M')
                            dp[
'G'-'A']=1;//倒G
                        else if(s[i+1][j]=='M')
                            dp[
'G'-'A']=1;//正G
                        else if(s[i+6][j]=='1')
                            dp[
'U'-'A']=1;
                        
else dp['P'-'A']=1;


                    


                    }

                    
else if(cnt==40)
                    
{
                        
if(s[i][j+5]=='M')
                            dp[
'O'-'A']=1;
                        
else if(s[i][j+3]=='M')
                            dp[
'V'-'A']=1;
                        
else if(s[i+1][j]=='M')
                            dp[
'W'-'A']=1;
                        
else 
                            dp[
'X'-'A']=1;
                    }

                    
else if(cnt==42)
                    
{

                        
if(s[i+1][j+3]=='M')
                            dp[
'N'-'A']=1;
                        
else
                            dp[
'D'-'A']=1;
                    }

                    
else if(cnt==43)
                    
{
                        
if(s[i][j+10]=='M')
                            dp[
'R'-'A']=1;
                        
else if(s[i][j+7])
                            dp[
'S'-'A']=1;
                        
else 
                            dp[
'R'-'A']=1;
                    }

                }

                    



            }

        }


        
for(i=0;i<26;i++)
        
{
            
if(dp[i]==1)
                printf(
"%c",'A'+i);
        }

        printf(
"\n");



    }

    
return 0;
}


很幼稚的想数个数,加判重。做到后来发现,有点困难,字母相互重叠的时候有可能会判错。应该多思考一下再写的。

posted on 2010-04-10 17:56 abilitytao 阅读(1098) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理