【题解】AT2043 AND Grid

【题解】AT2043 AND Grid

我们考虑直接构造两个互补的图切分别联通的图,然后原图有的大家都有就构造完成了。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<bitset>
#include<vector>
#include<map>
#include<ctime>
#include<cstdlib>
#include<set>
#include<bitset>
#include<stack>
#include<list>
#include<cmath>
using namespace std;
#define RP(t,a,b) for(register int (t)=(a),edd_=(b);t<=edd_;++t)
#define DRP(t,a,b) for(register int (t)=(a),edd_=(b);t>=edd_;--t)
#define ERP(t,a) for(int t=head[a];t;t=e[t].nx)
#define Max(a,b) ((a)<(b)?(b):(a))
#define Min(a,b) ((a)<(b)?(a):(b))
#define TMP template<class ccf>
#define lef L,R,l,mid,pos<<1
#define rgt L,R,mid+1,r,pos<<1|1
#define midd register int mid=(l+r)>>1
#define chek if(R<l||r<L)return
#define all 1,n,1
#define pushup(x) seg[(x)]=seg[(x)<<1]+seg[(x)<<1|1]
typedef long long ll;
TMP inline ccf qr(ccf k){
    char c=getchar();
    ccf x=0;
    int q=1;
    while(c<48||c>57)
    q=c==45?-1:q,c=getchar();
    while(c>=48&&c<=57)
    x=x*10+c-48,c=getchar();
    if(q==-1)
    x=-x;
    return x;
}
const int maxn=505;
bool g1[maxn][maxn];
int m,n;

inline bool qrqr(){
    char c=getchar();
    while(c!='.'&&c!='#')
    c=getchar();
    return c=='#';
}


int main(){
    n=qr(1);
    m=qr(1);
    RP(t,1,n)
    RP(i,1,m)
    g1[t][i]=qrqr();

    RP(t,1,n){
    RP(i,1,m)
        if(g1[t][i]||((t&1)&&i!=m)||i==1)
        cout<<'#';
        else
        cout<<'.';
    cout<<endl;
    }putchar('
');
    RP(t,1,n){
    RP(i,1,m)
        if(g1[t][i]||((!(t&1))&&i!=1)||i==m)
        cout<<'#';
        else
        cout<<'.';
    cout<<endl;
    }
    return 0;
}



原文地址:https://www.cnblogs.com/winlere/p/10333047.html