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;
}
}