Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴代码

Posted by husanfeng at 2012-11-17 13:16:48 on Problem 1099
Case i,i忘记++了,WA了一次
直接模拟:
#include <cstdlib>
#include <iostream>

using namespace std;

const int maxn=16;

int map[maxn][maxn];
int mark[maxn][maxn];
bool visit[maxn*4+5];

int main(void)
{
    int n,t=1;
    while(scanf("%d",&n)==1)
    {
        if(n==0) break;
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                mark[i][j]=2;        
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                scanf("%d",&map[i][j]);
        printf("Case %d:\n\n",t);
        for(int i=1;i<=4*n+3;i++)
        {
            printf("*");
        }
        printf("\n");
        for(int i=1;i<=4*n-3;i++)
        {
            for(int j=0;j<=4*n+1;j++)
                visit[j]=false;    
            printf("*");
            if(i%4==1)
            {
                for(int j=1;j<=4*n+1;j++)
                {
                    if(j%4==1)
                    {
                        printf("H");
                        if(visit[j-1])
                            visit[j]=true;
                    }           
                    if(j%4==3)
                    {
                        printf("O");
                        if(visit[j-1])
                            visit[j]=true;
                    }
                    if(j==2)
                    {
                        printf("-");
                        visit[1]=true;
                        visit[2]=true;
                    }
                    else if(j%4==2)
                    {
                        if(map[(i-1)/4+1][(j-1)/4+1]==-1)
                            printf(" "); 
                        else if(map[(i-1)/4+1][(j-1)/4+1]==1)
                        {
                            printf("-");
                            visit[j-1]=true;
                            visit[j]=true;
                            visit[j+1]=true;
                        }                          
                        else if(visit[j-1])
                            printf(" ");
                        else
                        {
                             printf("-");
                             visit[j-1]=true;
                             visit[j]=true;
                             visit[j+1]=true;
                        }
                    }
                    else if(j%4==0)
                    {
                        if(map[(i-1)/4+1][j/4]==-1)
                            printf(" "); 
                        else if(map[(i-1)/4+1][j/4]==1)
                        {
                            printf("-");
                            visit[j]=true;
                        }
                        else if(!visit[j-1])
                        {
                            printf("-");
                            visit[j-1]=true;
                            visit[j]=true;
                        }
                        else printf(" ");  
                    }                                          
                }
                for(int j=1;j<=n;j++)
                {
                    if(map[(i-1)/4+1][j]==1) mark[(i-1)/4+1][j]=0;
                    else if(map[(i-1)/4+1][j]!=-1) mark[(i-1)/4+1][j]--;
                }                                      
            }
            else if(i%4==2)
            {
                for(int j=1;j<=4*n+1;j++)
                {
                    if(j%4==3)
                    {
                        if(mark[(i-1)/4+1][(j-1)/4+1]!=0)      
                            printf("|");
                        else printf(" ");
                    }
                    else printf(" ");
                }                       
            }
            else if(i%4==3)
            {
                for(int j=1;j<=4*n+1;j++)
                {      
                    if(j%4==3) printf("H");
                    else printf(" ");
                }
            }
            else if(i%4==0)
            {
                for(int j=1;j<=4*n+1;j++)
                {
                    if(j%4==3&&mark[(i-1)/4+1][(j-1)/4+1]==0)
                    {        
                        printf("|");
                        mark[i/4+1][(j-1)/4+1]--;
                    }
                    else printf(" ");
                }
            }                         
            printf("*\n");
        }                   
        for(int i=1;i<=4*n+3;i++)
        {
            printf("*");
        }
        printf("\n\n");
        t++;
    }                                                             
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator