K-Nice


Time Limit: 1 Second      Memory Limit: 32768 KB      Special Judge


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 nmk (2
<= nm <= 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
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
int n,m,k;
int a[20][20];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
int p=1;int q=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
a[i][j]=1;
}
}
for(int i=1;i<=k;i++)
{
a[p][q]=0;
for(int k=0;k<4;k++)
{
a[p+dir[k][0]][q+dir[k][1]]=0;
}
if(q==m-2)
{
p++;
q=1;
}
else
{
q++;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(j!=m-1)
printf("%d ",a[i][j]);
else
printf("%d\n",a[i][j]);
}
}
}
return 0;
}

ZOJ 3212 K-Nice的更多相关文章

  1. ZOJ 3212 K-Nice(满足某个要求的矩阵构造)

    H - K-Nice Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

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

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

  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. django模型操作

    Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表        

  6. ZOJ 2112 Dynamic Rankings(动态区间第 k 大+块状链表)

    题目大意 给定一个数列,编号从 1 到 n,现在有 m 个操作,操作分两类: 1. 修改数列中某个位置的数的值为 val 2. 询问 [L, R] 这个区间中第 k 大的是多少 n<=50,00 ...

  7. ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  8. ZOJ 2112 Dynamic Rankings(带修改的区间第K大,分块+二分搜索+二分答案)

    Dynamic Rankings Time Limit: 10 Seconds      Memory Limit: 32768 KB The Company Dynamic Rankings has ...

  9. ZOJ -2112 Dynamic Rankings 主席树 待修改的区间第K大

    Dynamic Rankings 带修改的区间第K大其实就是先和静态区间第K大的操作一样.先建立一颗主席树, 然后再在树状数组的每一个节点开线段树(其实也是主席树,共用节点), 每次修改的时候都按照树 ...

随机推荐

  1. 【转】WebService 的创建,部署和使用

    WebService,即Web服务,能使得运行在不同机器上的不同应用无须借助,专门的第三方软件或硬件,就可相互交换数据或集成. 第一次选择WebService,是为了替代数据库远程连接.我们都知道当S ...

  2. 优矿众包对冲基金计划”优选策略---100w实盘资金管理权!!

    https://uqer.io/contest/ http://www.cnblogs.com/dunitian/p/4939369.html 优连

  3. 好的API设计

    [非原创,原文链接] API设计书籍下载: 1.keynote.pdf 2.api-design.pdf 最近在重构公司的一个交互中间件,在重新设计API及总体架构的时候思考了许多, 不禁萌发了一个疑 ...

  4. js 补零方法,如果不足位数

    var pad = function() { var tbl = []; return function(num, n) { var len = n-num.toString().length; if ...

  5. log4j配置 logging.xml (转载)

    Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行环境 ...

  6. 数据库ADO方式读取图片

    void Caccess_test_1Dlg::OnBnClickedButton3()//将偏振图像存入数据库 { // TODO: 在此添加控件通知处理程序代码 if (!PathFileExis ...

  7. DM8168 PWM驱动与測试程序

    昨天把DM8168的Timer设置给摸了一遍,为写PWM的底层驱动做好了准备,如今就要进入主题了. dm8168_pwm.c: #include <linux/module.h> #inc ...

  8. 查看系统资源使用情况:vmstat

    vmstat命令可以动态地查看系统资源的使用情况,如内存/交换分区/CPU的使用情况,通过使用该命令可以判断系统的瓶颈在哪里: [root@localhost ~]$ vmstat 1 5 # 表示每 ...

  9. WAS的部署

    一.设置JAM参数 1.登录WAS的控制台 https://192.168.0.91:9043/ibm/console

  10. LeetCode——N-Queens

    Description: The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that n ...