HDU - 6554
wls 有一个 n ∗ m 的网格,他现在想用俄罗斯方块中的"凸"型密铺它。一个"凸"型占四个格子,你可以随意把它调成上下左右四个方向中的一个。密铺的定义是网格中任意一个格子被且只被一个"凸"型铺到,并且这些"凸"型不能铺出网格的边界。
随意输出一组解即可。
Input
一行两个整数 n, m。
1 ≤ n, m ≤ 12
Output
无解输出 no response。
如果有解,输出 n 行,每行 m 个字符。你只能使用 1, 2, 3, 4 这四个字符,由同 一字符组成的四连通块被视为一个"凸"型。
如果有多组解,那么输出任意一种即可。
Sample Input
4 4
Sample Output
1113
2133
2243
2444
思路分析:
一定要说的话,还可以叫构造,实际上基础的矩形单位是4X4的方块。
代码:
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#define INF 0x3f3f3f3f
#define MAX 200100
#define ll long long
#define N 10010
using namespace std;
int n, m;
int ans[14][14];
void init()
{
ans[0][0] = ans[0][1] = ans[0][2] = ans[1][1] = 1;
ans[1][0] = ans[2][0] = ans[3][0] = ans[2][1] = 2;
ans[0][3] = ans[1][3] = ans[2][3] = ans[1][2] = 3;
ans[3][1] = ans[3][2] = ans[3][3] = ans[2][2] = 4;
}
void print(int i)
{
for(int j = 0; j < m; j++)
{
printf("%d", ans[i][j % 4]);
}
printf("\n");
}
int main()
{
ans[14][14] = {0};
while(scanf("%d%d", &n, &m) != EOF)
{
init();
if (n % 4 != 0 || m % 4 != 0)
{
printf("no response\n\n");
}
else
{
for(int i = 0; i < n; i++)
{
print(i % 4);
}
printf("\n");
}
}
return 0;
}
两个\n,我服了!