ZOJ 3212 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
这样构造
#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(满足某个要求的矩阵构造)的更多相关文章
- ZOJ 3632 K - Watermelon Full of Water 优先队列优化DP
K - Watermelon Full of Water Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%lld &am ...
- ZOJ 3212 K-Nice
K-Nice Time Limit: 1 Second Memory Limit: 32768 KB Special Judge This is a super simple pr ...
- zoj 3212 K-Nice(构造)
K-Nice Time Limit: 1 Second Memory Limit: 32768 KB Special Judge This is a super simple pr ...
- ZOJ 3599 K倍动态减法游戏
下面的文字辅助理解来自http://blog.csdn.net/tbl_123/article/details/24884861 博弈论中的 K倍动态减法游戏,难度较大,参看了好多资料才懵懂! 此题可 ...
- poj 3613 经过k条边最短路 floyd+矩阵快速幂
http://poj.org/problem?id=3613 s->t上经过k条边的最短路 先把1000范围的点离散化到200中,然后使用最短路可以使用floyd,由于求的是经过k条路的最短路, ...
- ZOJ 3256 Tour in the Castle 插头DP 矩阵乘法
题解 这题是一道非常好的插头题,与一般的按格转移的题目不同,由于m很大,要矩阵乘法,这题需要你做一个按列转移的插头DP. 按列转移多少与按格转移不同,但大体上还是基于连通性进行转移.每一列只有右插头是 ...
- 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 ...
- ZOJ - 2671 Cryptography(线段树+求区间矩阵乘积)
题意:已知n个矩阵(下标从1开始),求下标x~y区间矩阵的乘积.最多m次询问,n ( 1 <= n <= 30,000) and m ( 1 <= m <= 30,000). ...
- 机器学习PR:k近邻法分类
k近邻法是一种基本分类与回归方法.本章只讨论k近邻分类,回归方法将在随后专题中进行. 它可以进行多类分类,分类时根据在样本集合中其k个最近邻点的类别,通过多数表决等方式进行预测,因此不具有显式的学习过 ...
随机推荐
- 自定义指令directive基础用法
官方链接:http://doc.vue-js.com/v2/guide/custom-directive.html#simplest-directive-example 在main.js中注册自定义指 ...
- spring shiro 集成
1.向spring项目中添加shiro相关的依赖 <dependency> <groupId>commons-logging</groupId> <artif ...
- logminer系列文章一(logminer的使用)
转自 http://blog.itpub.net/26613085/viewspace-1064008/ 1.安装logminer以及生成logminer数据字典所需要的包(需使用sys用户) [or ...
- 登录MySQL提示ERROR 1045 (28000)错误解决方法
今天,登录服务器准备修改数据库的一些东西.但输入密码,却进不了数据库并提示一个错误,如下图 再确认密码没错的情况下,还是进不了数据库.便在网上找到了解决方法,记录下来,供参考学习. 解决方法: 总体思 ...
- PHP接收IOS post过来的json数据无法解析的问题
在本地环境下运行解析OK 换到线上的环境解析失败 开始怀疑各种编码问题,解决均无效. 查看phpinfo 发现magic_quotes_gpc =on 终于找到问题所在,更改php.ini文件 mag ...
- leveldb源码分析--WriteBatch
从[leveldb源码分析--插入删除流程]和WriteBatch其名我们就很轻易的知道,这个是leveldb内部的一个批量写的结构,在leveldb为了提高插入和删除的效率,在其插入过程中都采用了批 ...
- paramiko的安装与使用
paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接,支持在远程登录服务器执行命令和上传下载文件的功能. 安装 pycrypto下载地址: ...
- node环境和浏览器的区别
一.全局环境下this的指向 在node中this指向global而在浏览器中this指向window,这就是为什么underscore中一上来就定义了一 root: 1 var root = typ ...
- JQuery 常用命令总结
下面介绍在jQuery中设置form表单中action的值的方法. $("#myFormId").attr("action", "userinfo.s ...
- [翻译] NSDate-TimeAgo
NSDate-TimeAgo https://github.com/kevinlawler/NSDate-TimeAgo NSDate+TimeAgo has merged with DateTool ...