CodeForces - 990D Graph And Its Complement

这道题是一道构造

可惜我看了题解才会

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
inline int read(){
	int x=0,f=1,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
char ch1='1',ch2='0';
int main(){
	int n=read(),a=read(),b=read();
	if(a!=1&&b!=1){
		puts("NO");
		return 0;
	}
	if((a==1&&b==1&&(n==2||n==3))||a>n||b>n){
		puts("NO");
		return 0;
	}
	puts("YES");
	if(a==1) swap(a,b),swap(ch1,ch2);
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++) printf("%c",(i==j)?'0':((i+1==j&&j>=a)||(j+1==i&&i>=a)?ch1:ch2));
		puts("");
	}
	return 0;
}

  

posted @ 2019-03-04 15:31  古城独钓  阅读(146)  评论(0编辑  收藏  举报