繁华模拟赛 奇怪的棋

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 205;
struct chs{
    int y;
    int x;
    
};
chs orz[3][maxn*maxn];
int n,vis[maxn][maxn],cnt_op,cnt_no,cnt_ok;
int dy,dx,ans;
void input(){
    cin>>n;
    char cmd;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            scanf("%c",&cmd);
            while(cmd != 'o' && cmd != 'x' && cmd != '.') scanf("%c",&cmd);
            if(cmd == 'o'){
                cnt_op++;
                orz[0][cnt_op].y = i;
                orz[0][cnt_op].x = j;
            }else if(cmd == 'x'){
                cnt_ok++;
                orz[1][cnt_ok].y = i;
                orz[1][cnt_ok].x = j;
            }else if(cmd == '.'){
                cnt_no++;
                orz[2][cnt_no].y = i;
                orz[2][cnt_no].x = j;
            }
        }
    }
}
void get_d(int y,int x,int ny,int nx){
    dy = n + ny - y;
    dx = n + nx - x;
}
void get_no(){
    for(int i = 1;i <= cnt_no;i++){
        for(int j = 1;j <= cnt_op;j++){
            get_d(orz[0][j].y,orz[0][j].x,orz[2][i].y,orz[2][i].x);
            vis[dy][dx] = 2;
        }
    }
}
bool get_ok(int dep){
    if(dep > cnt_ok){
        cout<<"YES"<<endl;
        for(int i = 1;i <= 2 * n - 1;i++){
            for(int j = 1;j <= 2 * n - 1;j++){
                if(i == n && j == n) printf("o");
                else if(vis[i][j] == 2) printf(".");
                else printf("x");
            }
            printf("\n");
        }
        return true;
    }
    int ndy,ndx;
    for(int i = 1;i <= cnt_op;i++){
        get_d(orz[0][i].y,orz[0][i].x,orz[1][dep].y,orz[1][dep].x);
        ndy = dy;
        ndx = dx;
        if(vis[ndy][ndx] != 2){
            vis[ndy][ndx] = 1;
            if(get_ok(dep+1)) return true;
            vis[ndy][ndx] = 0;
        }
    }
    return false;
}
int main(){
    freopen("chess.in","r",stdin);
    freopen("chess.out","w",stdout);
    input();
    get_no();
    if(!get_ok(1)) cout<<"NO";
    return 0;
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstdlib>
#include<string>
#include<bitset>
#define INF 1000000000
#define N 100005
#define fi first
#define se second
#define debug(x) cout<<#x<<"="<<x<<endl
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
int z,n,ans[105][105];
char mp[55][55];
bool vis[55][55];
bool check(int x,int y)
{
    if(x>0&&y>0&&x<=n&&y<=n)
        return 1;
    return 0;
}
int main()
{
    int i,j,r,c,now,tx,ty;
    freopen("chess.in","r",stdin);
    freopen("chess.out","w",stdout);
    cin>>n;
    for(i=1;i<=n;i++)
        scanf("%s",mp[i]+1);
    for(i=-n+1;i<n;i++)
        for(j=-n+1;j<n;j++)
        {
            now=0;
            for(r=1;r<=n;r++)
                for(c=1;c<=n;c++)
                    if(mp[r][c]=='o')
                    {
                        tx=r+i,ty=c+j;
                        if(check(tx,ty))
                            if(mp[tx][ty]=='.')
                                if(!now)
                                    now=-1;
                    }
            ans[i+n][j+n]=now;
            if(now!=-1)
            {
                for(r=1;r<=n;r++)
                for(c=1;c<=n;c++)
                    if(mp[r][c]=='o')
                    {
                        tx=r+i,ty=c+j;
                        if(check(tx,ty))
                            vis[tx][ty]=1;
                    }
            }
        }
    for(r=1;r<=n;r++)
        for(c=1;c<=n;c++)
            if(mp[r][c]=='x'&&!vis[r][c])
            {
                printf("NO\n");
                return 0;
            }
    printf("YES\n");
    for(i=1;i<n*2;i++)
    {
        for(j=1;j<n*2;j++)
        {
            if(i==n&&j==n)
            {
                printf("o");
                continue;
            }
            if(ans[i][j]<0)
                printf(".");
            else printf("x");
        }
        cout<<endl;
    }
    return 0;
}
// davidlee1999WTK 2015/
// srO myk Orz
//ios::sync_with_stdio(false);

 

posted @ 2016-09-15 18:16  ACforever  阅读(301)  评论(0编辑  收藏  举报