H - K-Nice

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Description

This is a super simple problem. The description is simple, the solution is simple. If you believe so, just read it on. Or if you don't, just pretend that you can't see this one.

We say an element is inside a matrix if it has four neighboring elements in the matrix (Those at the corner have two and on the edge have three). An element inside a matrix is called "nice" when its value equals the sum of its four neighbors. A matrix is called "k-nice" if and only if k of the elements inside the matrix are "nice".

Now given the size of the matrix and the value of k, you are to output any one of the "k-nice" matrix of the given size. It is guaranteed that there is always a solution to every test case.

Input

The first line of the input contains an integer T (1 <= T <= 8500) followed by T test cases. Each case contains three integers n, m, k (2 <= n, m <= 15, 0 <= k <= (n - 2) * (m - 2)) indicating the matrix size n * m and it the "nice"-degree k.

Output

For each test case, output a matrix with n lines each containing m elements separated by a space (no extra space at the end of the line). The absolute value of the elements in the matrix should not be greater than 10000.

Sample Input

2
4 5 3
5 5 3

Sample Output

2 1 3 1 1
4 8 2 6 1
1 1 9 2 9
2 2 4 4 3
0 1 2 3 0
0 4 5 6 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
题目意思:
构造出一个含有k个nice点的n*m的矩阵
nice点:周围四个数字之和等于该数字
分析:
不在边缘和角处构造
这样简单一点
先全部初始化-1
0的点其周围4个全为0
这样构造
之和将等于-1的点替换成1
这样就构造完毕
 
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define eps 10e-6
#define INF 999999999
#define max_v 25
int a[max_v][max_v];
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
memset(a,-,sizeof(a));
for(int i=;i<n-;i++)
{
for(int j=;j<m-;j++)
{
if(k<=)
break;
if(a[i][j]<=)
{
k--;
a[i][j]=;
a[i+][j]=;
a[i-][j]=;
a[i][j+]=;
a[i][j-]=;
}
}
if(k<=)
break;
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]<)
a[i][j]=;
}
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(j==)
printf("%d",a[i][j]);
else
printf(" %d",a[i][j]);
}
printf("\n");
}
}
return ;
}
/* 题目意思:
构造出一个含有k个nice点的n*m的矩阵
nice点:周围四个数字之和等于该数字 分析:
不在边缘和角处构造
这样简单一点
先全部初始化-1
0的点其周围4个全为0
这样构造 之和将等于-1的点替换成1 这样就是构造完毕 */
 

ZOJ 3212 K-Nice(满足某个要求的矩阵构造)的更多相关文章

  1. ZOJ 3632 K - Watermelon Full of Water 优先队列优化DP

    K - Watermelon Full of Water Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld &am ...

  2. ZOJ 3212 K-Nice

    K-Nice Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge This is a super simple pr ...

  3. zoj 3212 K-Nice(构造)

    K-Nice Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge This is a super simple pr ...

  4. ZOJ 3599 K倍动态减法游戏

    下面的文字辅助理解来自http://blog.csdn.net/tbl_123/article/details/24884861 博弈论中的 K倍动态减法游戏,难度较大,参看了好多资料才懵懂! 此题可 ...

  5. poj 3613 经过k条边最短路 floyd+矩阵快速幂

    http://poj.org/problem?id=3613 s->t上经过k条边的最短路 先把1000范围的点离散化到200中,然后使用最短路可以使用floyd,由于求的是经过k条路的最短路, ...

  6. ZOJ 3256 Tour in the Castle 插头DP 矩阵乘法

    题解 这题是一道非常好的插头题,与一般的按格转移的题目不同,由于m很大,要矩阵乘法,这题需要你做一个按列转移的插头DP. 按列转移多少与按格转移不同,但大体上还是基于连通性进行转移.每一列只有右插头是 ...

  7. numpy.ones_like(a, dtype=None, order='K', subok=True)返回和原矩阵一样形状的1矩阵

    Return an array of ones with the same shape and type as a given array. Parameters: a : array_like Th ...

  8. ZOJ - 2671 Cryptography(线段树+求区间矩阵乘积)

    题意:已知n个矩阵(下标从1开始),求下标x~y区间矩阵的乘积.最多m次询问,n ( 1 <= n <= 30,000) and m ( 1 <= m <= 30,000). ...

  9. 机器学习PR:k近邻法分类

    k近邻法是一种基本分类与回归方法.本章只讨论k近邻分类,回归方法将在随后专题中进行. 它可以进行多类分类,分类时根据在样本集合中其k个最近邻点的类别,通过多数表决等方式进行预测,因此不具有显式的学习过 ...

随机推荐

  1. html基础-标题标签-文字标签(2)

    昨天说道了我的第一个网页,今天接着继续带大家深入,前期学习千万不要用代码工具哦!那样就少了深入了解的机会了哦! 一.大家都知道文章会有各种标题,网页其实也跟文章差不多也有专门来写标题的元素. (1). ...

  2. 了解JS

    什么是js? JS,是JavaScript的缩写形式,JavaScript是一种基于对象和事件驱动并且具有相对 安全性的客户端脚本语言. 借用java之名,但和java没有关系 javascript历 ...

  3. fuzz系列之afl

    afl 实战 前言 像 libFuzzer, afl 这类 fuzz 对于 从文件 或者 标准输入 获取输入的程序都能进行很好的 fuzz, 但是对于基于网络的程序来说就不是那么方便了. 这篇文章介绍 ...

  4. 一步一步 Pwn RouterOS之调试环境搭建&&漏洞分析&&poc

    前言 本文由 本人 首发于 先知安全技术社区: https://xianzhi.aliyun.com/forum/user/5274 本文分析 Vault 7 中泄露的 RouterOs 漏洞.漏洞影 ...

  5. Base64编码和解码实现

    function Base64() { // private property _keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqr ...

  6. Django 多表查询 聚合查询 分组查询 F查询 Q查询

    # -------------------------------------------------------------------------------------------------- ...

  7. 聊一聊数组的map、reduce、foreach等方法

    聊聊数组遍历方法 JS 数组的遍历方法有好几个: every some filter foreach map reduce 接下来我们来一个个地交流下. every() arr.every(callb ...

  8. LeetCode题解之Missing Number

    1.题目描述 2.题目分析 将 [ 0 , n ]之间的整数放到 n 个元素的数组中去,必然缺失一个元素.在一次遍历中,将元素n[i] 放到 n[ n[i] ] ,位置.最后检查元素值和下标不相等的情 ...

  9. Prometheus Node_exporter metrics 之 Basic CPU / Mem / Disk Info

    Basic CPU / Mem / Disk Info 1. CPU Cores 物理 CPU 的核数 cat /proc/cpuinfo| grep "cpu cores"| u ...

  10. Linux 运维工程师一定要知道的六类好习惯和23个教训

    一.线上操作规范 1.测试使用当初学习Linux的使用,从基础到服务到集群,都是在虚拟机做的,虽然老师告诉我们跟真机没有什么差别,可是对真实环境的渴望日渐上升,不过虚拟机的各种快照却让我们养成了各种手 ...