Holding Two

Given n, m, construct a matrix A of size n × m, whose entries are all either 0 or 1, and no three distinct entries Ai1,j1 , Ai2,j2 , Ai3,j3 satisfying that Ai1,j1 = Ai2,j2 = Ai3,j3 , −1 ≤ i1 − i2 = i2 − i3 ≤ 1, −1 ≤ j1 − j2 = j2 − j3 ≤ 1. If multiple solutions exist, print any one of them. If no solution, print “-1” in one line. Input Input only one line containing two integers n, m (1 ≤ n, m ≤ 1000). Output If solutions exist, print n lines each containing a 01-string of length m, denoting the matrix you construct. If no solution, print “-1” in one line.

Example standard

input

3 3

output

110

001

100

题意就是不能有连续的三个相等的字符

001100110011

110011001100

………………

………………

这样排就满足题意

#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	string s="";
	string s1="";
	int k;
	for(int i=0;i<m;i++)
	{
		k=i/2;
		if(k%2==1)
		s+='1';
		else
		s+='0';
	}
	for(int i=0;i<m;i++)
	{
		k=i/2;
		if(k%2==1)
		s1+='0';
		else
		s1+='1';
	}
	for(int i=1;i<=n;i++)
	{
		if(i%2==1)
		cout<<s<<endl;
		else
		cout<<s1<<endl;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值