uva 11520 - Fill the Square - D 填方块 贪心



贪心,从上到下,从左到右,能填A则填A,否则试B...

#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int INF =0x3f3f3f3f;
const int maxm=100000    ;

int n,m;
char s[maxm+5];
char a[12][maxm+5];


int dir[4][2]={{-1,0},{+1,0},{0,-1},{0,+1} };
bool vis[30];

bool in(int &y,int &x)
{
    return 0<=y&&y<n&&0<=x&&x<m;
}

char find()
{
    for(int i=0;i<26;i++)
    {
        if(!vis[i])
        {
            return 'A'+i;
        }

    }


}
void work()
{
    for(int y=0;y<n;y++)
    {
        for(int x=0;x<m;x++)
        {
            if(a[y][x]!='.')  continue;
            memset(vis,0,sizeof vis);
            for(int j=0;j<4;j++)
            {

                int ty=y+dir[j][0];
                int tx=x+dir[j][1];
                if(!in(ty,tx)||a[ty][tx]=='.')  continue;
                int t=a[ty][tx]-'A';
                vis[t]=1;

            }
            char ch=find();
            a[y][x]=ch;

        }
    }
}
int main()
{
   int T,kase=0;
   scanf("%d",&T);
   while(T--)
   {
       scanf("%d",&n);

       for(int i=0;i<n;i++)
       {
           scanf("%s",a[i]);
       }
       m=strlen(a[0]);

       work();
       printf("Case %d:\n",++kase);
        for(int y=0;y<n;y++)
     {
        for(int x=0;x<m;x++)
        {

            putchar(a[y][x]);

        }
        putchar('\n');
     }
   }
   return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值