More than 2019 cattle off summer school camp (sixth) E structure, the same original composition complement graph

https://ac.nowcoder.com/acm/contest/886#question

Meaning no question asked whether there is a point in the n-graph G is H with its complement FIG composition, if present in the adjacency matrix G and output H of the G map.

Analytic Construction of questions, the answer is not unique. FIG picture and the number of edges to complement the same, so that n = 4 * k + 2, and 4 * k + 3 when no solution

When n = 4 * k to 4 points into portions P1, all of the points P2, P3, P4 before the two parts of two connected side P1P2 two group composition, and even between the two two part edge portion and P3P1, P4P2 between the portion and the portion twenty-two even side

FIG its complement is composed of groups P3P4, P4P1 between the connected edges between connected side P3P2, isomorphic with the original.

Mapping between blocks, picture P1P2P3P4 FIG P3P4P2P1 complement or other schemes.

When n = 4 * k + 1 and the remaining two blocks of a random point even enough.

Code

//B
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e3+10;
int g[maxn][maxn];
int main()
{
    int t,n,kase=1;
    cin>>t;
    while(t--){
        cin>>n;
        memset(g,0,sizeof(g));
        printf("Case #%d: ",kase++);
        if(n%4==2||n%4==3){
            cout<<"No"<<endl;
            continue;
        }
        else {
            cout<<"Yes"<<endl;
            int block=n/4;
            for(int i=1;i<=block;i++){
                for(int j=block+1;j<=2*block;j++)
                    g[i][j]=g[j][i]=1;
                for(int j=2*block+1;j<=3*block;j++)
                    g[i][j]=g[j][i]=1;
                for(int j=i+1;j<=block;j++)
                    g[i][j]=g[j][i]=1;
            }
            for(int i=block+1;i<=2*block;i++){
                for(int j=3*block+1;j<=4*block;j++)
                    g[i][j]=g[j][i]=1;
                for(int j=i+1;j<=2*block;j++)
                    g[i][j]=g[j][i]=1;
            }
            if(n%4==1){
                for(int i=1;i<=2*block;i++)
                    g[i][n]=g[n][i]=1;
                for(int i=1;i<=n;i++){
                    for(int j=1;j<=n;j++)
                        printf("%d",g[i][j]);
                    printf("\n");
                }
                for(int i=2*block+1;i<=4*block;i++)
                    printf("%d ",i);
                for(int i=2*block;i>=1;i--)
                    printf("%d ",i);
                printf("%d\n",n);
            }
            else{
                for(int i=1;i<=n;i++){
                    for(int j=1;j<=n;j++)
                        printf("%d",g[i][j]);
                    printf("\n");
                }
                for(int i=2*block+1;i<=4*block;i++)
                    printf("%d ",i);
                for(int i=2*block;i>=1;i--)
                    printf("%d%c",i,i==1?'\n':' ');
            }
        }

    }
}

 

Guess you like

Origin www.cnblogs.com/stranger-/p/11298938.html