Codeforces Round #191 (Div. 2) D

来源:互联网 发布:淘宝网的古悦堂怎么样 编辑:程序博客网 时间:2024/04/26 12:55

先全部B

搜索,每次回溯的时候先D后R,第一块不拆依旧为蓝色

#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>using namespace std;struct node{    int x,y;    int val;    char color;} step[5555555];int n,m,ans;char mp[555][555];bool v[555][555];int mx[4] = {-1,1,0,0};int my[4] = {0,0,1,-1};bool in(int x,int y){    if(x >= 1 && x <= n && y >= 1 && y <= m)    {        return true;    }    else    {        return false;    }}void dfs(int x, int y){    v[x][y] = 1;    for(int i = 0 ; i < 4 ; i ++){        int a = x + mx[i];        int b = y + my[i];        if(in(a,b) && v[a][b] == 0 && mp[a][b] == 'B')        {            dfs(a,b);        }    }    step[ans].x = x;    step[ans].y = y;    step[ans].color = 'D';    ans++;    step[ans].x = x;    step[ans].y = y;    step[ans].color = 'R';    ans++;}int main(){    scanf("%d%d",&n,&m);    memset(v,0,sizeof(v));    for(int i = 1 ; i <= n ; i ++)    {        for(int j = 1 ; j <= m ; j ++)        {            cin>>mp[i][j];        }    }    ans = 0;    for(int i = 1 ; i <= n ; i ++)    {        for(int j = 1 ; j <= m ; j ++)        {            if(mp[i][j] == '#')            {                continue;            }            step[ans].x = i;            step[ans].y = j;            step[ans].color = 'B';            mp[i][j] = 'B';            ans++;        }    }    for(int i = 1 ; i <= n ; i ++){        for(int j = 1 ; j <= m ; j ++){            if(v[i][j] || mp[i][j] == '#')                continue;            v[i][j] = 1;            for(int k = 0 ; k < 4 ; k ++)            {                int a = i + mx[k];                int b = j + my[k];                if(in(a,b) && v[a][b] == 0 && mp[a][b] != '#')                {                    dfs(a,b);                }            }        }    }    cout<<ans<<endl;    for(int i = 0 ; i < ans ; i ++)    {        printf("%c %d %d\n",step[i].color,step[i].x,step[i].y);    }    return 0;}


原创粉丝点击