[Simulation] Suzhou National Camp Day2 A.divide

Topic Link

 

Meaning of the questions:

  Among dyeing a grid line $ $ $ m $ n-columns, satisfy:

  1. The black grid two hundred twenty-four Unicom, two hundred twenty-four Unicom white lattice, and the lattice through the black and white can be rotated and translated to coincide with a lattice

  2. $ w (wx, wy) $ this lattice is white, $ b (bx, by) $ This grid is black.

  Required to find a solution to any, or no solution is determined. Multiple sets of data.

  $ 1 \ and T \ 10 ^ 3 \, 1 \ n, m \ 50, \, 1 \ and WX, bx \ n, \; 1 \ and Wyoming, by \ m, \; (WX, WY) \ neq (bx, by) $

 

analysis:

  First, think about when no solution.

  ① grid number is odd, not sharing

  ② only a single line / single row and specify black and white grid on the same side, can not be divided equally

 

  Next Category talk:

  ① If $ 2 | m $ (FIG rotatably through the entire $ 90 ^ {\ circ} $ obtained, the same below), and the two specified points separated midline, is directly cut.

 

  ② If the specified point living ipsilateral middle, and in different rows, can be stained as described above in FIG.

 

 

  ③ If the specified middle point living opposite side, and in the same line, from the specified point near the center line is not the last line, as shown above may be stained.

 

achieve:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#define IL inline
#define UI unsigned int
#define RI register int
using namespace std;
const int N=50;

IL void swap(int &x,int &y){
    int t=x;    x=y;    y=t;
}

    int T,n,m,wx,wy,bx,by;
    bool flag1,flag2,flag3,flag4;
    int nn,mm,c,d,x[2],y[2];
    int bod[N+3][N+3];

IL void step1(){
    if(n*m%2==1){
        flag1=true;    return ;        
    }
    
    x[0]=wx;    y[0]=wy;
    x[1]=bx;    y[1]=by;
    if(m%2==1){
        flag2=true;
        swap(n,m);
        for(int i=0;i<2;i++)
            swap(x[i],y[i]);
        
    }
    
    mm=m/2;
    if(n==1&&((y[0]<=mm&&y[1]<=mm)||(y[0]>mm&&y[1]>mm))){
        flag1=true;    return ;
    }
    
}

IL bool cmp1(){
    if(y[0]==y[1])
        return x[0]<x[1];
    return y[0]<y[1];
    
}

IL bool cmp2(){
    if(x[0]==x[1])
        return y[0]<y[1];
    return x[0]<x[1];
    
}

IL void sol1(){
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            bod[i][j]=(j<=mm)?c:d;
            
}

IL void sol2(){
    int vx[2];
    for(int i=0;i<2;i++)
        vx[i]=n-x[i];
        
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            bod[i][j]=(i<=(j<=mm?x[c]:vx[c]))?c:d;
            
}

IL void sol3(){
    int vx[2];
    for(int i=0;i<2;i++)
        vx[i]=n-x[i]+1;
        
    int vy[2];
    for(int i=0;i<2;i++)
        vy[i]=m-y[i]+1;
        
    memset(bod,-1,sizeof bod);
    for(int i=1;i<=x[d];i++)
        for(int j=y[d];j<=mm;j++)
            bod[i][j]=d;
            
    for(int i=vx[d];i<=n;i++)
        for(int j=mm+1;j<=vy[d];j++)
            bod[i][j]=c;
            
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        if(!~bod[i][j])
            bod[i][j]=(j<=mm)?c:d;
            
}

IL void step2(){
    c=cmp1()?0:1;    d=c^1;
    
    if(y[c]<=mm&&y[d]>mm){
        sol1();    return ;
    }
    
    if(y[c]>mm){
        flag3=true;
        for(int i=0;i<2;i++)
            y[i]=m-y[i]+1;
        
        c=cmp1()?0:1;    d=c^1;
        
    }
    
    if(x[d]==n){
        flag4=true;
        for(int i=0;i<2;i++)
            x[i]=n-x[i]+1;
            
    }
    
    c=cmp2()?0:1;    d=c^1;
    
    if(x[c]!=x[d])
        sol2();
    else 
        sol3();
    
}

IL void step3(){
    if(flag4)
        for(int i=1,ti=n;i<ti;i++,ti--)
            for(int j=1;j<=m;j++)
                swap(bod[i][j],bod[ti][j]);
    
    if(flag3)
        for(int i=1;i<=n;i++)
            for(int j=1,tj=m;j<=mm;j++,tj--)
                swap(bod[i][j],bod[i][tj]);
                
    if(flag2){
        int tmp[N+3][N+3];
        for(int i=1;i<=n;i++)
            for(int j=1;j<=m;j++)
                tmp[j][i]=bod[i][j];
        memcpy(bod,tmp,sizeof bod);
        swap(n,m);
        
    }
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++)
            printf("%d ",bod[i][j]);
        printf("\n");
        
    }
    
}

int main(){
    freopen("A.in","r",stdin);
    freopen("A.out","w",stdout);

    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d%d%d",&n,&m,&wx,&wy,&bx,&by);
        
        flag1=flag2=flag3=flag4=false;
        step1();
        if(flag1){
            printf("-1\n");    continue;
        }
        step2();
        step3();
        
    }

    return 0;

}
View Code

 

小结:

  简洁分类,转化简并。

 

Guess you like

Origin www.cnblogs.com/Hansue/p/11644291.html