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个最近邻点的类别,通过多数表决等方式进行预测,因此不具有显式的学习过 ...
随机推荐
- cf1000F. One Occurrence(线段树 set)
题意 题目链接 Sol (真后悔没打这场EDU qwq) 首先把询问离线,预处理每个数的\(pre, nxt\),同时线段树维护\(pre\)(下标是\(pre\),值是\(i\)),同时维护一下最大 ...
- Collection FrameWork
Collection FrameWork如下: Collection ├List │├LinkedList │├ArrayList │└Vector │ └Stack └Set Map ├Hashta ...
- Nginx的文件夹的别名设计&drupal简洁url
参考:nginx 官方drupal 配置 - Drupal | NGINX 环境:ubuntu14,Nginx1.12, MariaDB5.5.56,PHP7.1.7 需求:1.不同的网站,不要用文件 ...
- 关于redux
react将dom解耦,不用直接操作dom,使用了状态机制,当状态改变时视图就会相应更新.我们知道在react中,父组件可以将一些状态传递给子组件,让子组件的视图相应更新,这时我们会发现,只有有关联的 ...
- CSS3 选择器用法小结
表单选择器: /*:enabled 可用的 :disabled 被禁用的 :focus 获取了焦点的 多用在表单元素上*/ input:enabled {...} input:disabled {.. ...
- 通过Places API Web Service获取兴趣点数据
实验将爬取新加坡地区的银行POI数据 数据库采用mongodb,请自行安装,同时申请google的key 直接上代码 #coding=utf-8 import urllib import json i ...
- numpy深入理解剖析
http://www.scipy-lectures.org/advanced/advanced_numpy/index.html
- Jquery Ajax向服务端传递数组参数值
在使用MVC时,向服务器端发送POST请求时有时需要传递数组作为参数值 下面使用例子说明,首先看一下Action [HttpPost] public ActionResult Test(List< ...
- sql面试
1.用一条SQL语句 查询出每门课都大于80分的学生姓名 name kecheng fenshu 张三 语文 81张三 数学 75李四 语文 ...
- Linux系统更改/关闭防火墙
更改/关闭防火墙 查看当前防火墙状态 /etc/init.d/iptables status ==>service iptables status 打开防火墙 service iptables ...