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

看了题意后AC- - 还是懒得看英语

Posted by Ink213 at 2013-04-13 23:42:52 on Problem 1027
#include<cstdio>
#include<cstring>
using namespace std;
char map[20][25], np[20][25];
bool vis[11][16];
int max, num, col, row[16];
int dx[4]= {0,0,-1,1};
int dy[4]= {1,-1,0,0};
void dfs(int x,int y)
{
    int i, j, nx, ny;
    vis[x][y]=true;
    num++;
    for(i=0; i<4; i++)
    {
        nx=x+dx[i], ny=y+dy[i];
        if(nx<0||ny<0||ny>=col||nx>=row[ny]) continue;
        if(map[x][y]!=map[nx][ny]||vis[nx][ny]) continue;
        dfs(nx,ny);
    }
}
void update(int x,int y)
{
    int i, j, nx, ny;
    char temp=map[x][y];
    map[x][y]='#';
    for(i=0; i<4; i++)
    {
        nx=x+dx[i], ny=y+dy[i];
        if(nx<0||ny<0||ny>=col||nx>=row[ny]) continue;
        if(temp!=map[nx][ny]) continue;
        update(nx,ny);
    }
}
int main()
{
    int t, i, j, st, ed, ball, ncase=0, sum;
    scanf("%d",&t);
    while(t--)
    {
        sum=0;
        for(i=9; i>=0; i--)
        {
            for(j=0; j<15; j++)
            {
                scanf(" %c",&map[i][j]);
            }
        }
        ball=0, col=15;
        for(i=0; i<15; i++)
            row[i]=10;
        printf("Game %d:\n\n",++ncase);
        while(true)
        {
            max=0;
            memset(vis,0,sizeof(vis));
            for(j=0; j<col; j++)
            {
                for(i=0; i<row[j]; i++)
                {
                    if(!vis[i][j])
                    {
                        num=0;
                        dfs(i,j);
                        if(num>max)
                        {
                            st=i, ed=j;
                            max=num;
                        }
                    }
                }
            }
            if(max<2) break;
            printf("Move %d at (%d,%d): removed %d balls of color %c, got %d points.\n",++ball,st+1,ed+1,max,map[st][ed],(max-2)*(max-2));
            sum+=(max-2)*(max-2);
            update(st,ed);
            int top, len=0;
            for(j=0; j<col; j++)
            {
                top=0;
                for(i=0; i<row[j]; i++)
                {
                    if(map[i][j]!='#')
                    {
                        np[top++][len]=map[i][j];
                    }
                }
                if(top!=0)
                {
                    row[len]=top;
                    len++;
                }
            }
            col=len;
            for(j=0; j<col; j++)
            {
                for(i=0; i<row[j]; i++)
                {
                    map[i][j]=np[i][j];
                }
            }
        }
        int left=0;
        for(j=0; j<col; j++)
        {
            left+=row[j];
        }
        if(left==0) sum+=1000;
        printf("Final score: %d, with %d balls remaining.\n",sum,left);
        if(t>0) puts("");
    }
    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