H Holding Two
https://ac.nowcoder.com/acm/contest/11256/H
1.题意:输出一个n*m的矩阵,矩阵中满足在横行,竖行,斜行中,任意的连续的3个的元素不能都为0,或都为1;(英语不好,我看了半天没看到题意)
2.方法
构造一个这样的矩阵
0 0 1 1 0 0 1 1 ……
1 1 0 0 1 1 0 0 ……
0 0 1 1 0 0 1 1 ……
1 1 0 0 1 1 0 0 ……
0 0 1 1 0 0 1 1 ……
3.代码如下
#include <bits/stdc++.h>
using namespace std;
#define js ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll qpow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; }
ll qpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1)(ans *= a) %= mod; b >>= 1; (a *= a) %= mod; }return ans % mod; }
const int mod=1e9+7;
const int N=1e3+7;
int n,m;
int a[N][N];
void fun(){
for(int i=0;i<N;i++){
for(int j=0;j<N;j+=2){
if(i%2==0){
if(j%4==0) a[i][j]=a[i][j+1]=0;
else a[i][j]=a[i][j+1]=1;
}
else{
if(j%4==0) a[i][j]=a[i][j+1]=1;
else a[i][j]=a[i][j+1]=0;
}
}
}
}
int main(){
fun();
while(cin>>n>>m){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cout<<a[i][j];
}
cout<<endl;
}
}
return 0;
}
京公网安备 11010502036488号