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. Hibernate一级缓存、二级缓存以及查询缓存的关系

    转载自http://blog.csdn.net/maoyeqiu/article/details/50209893 前两天总结了一下二级缓存和查询缓存的关系,但是又有一个新的问题,就是查询缓存缓存到二 ...

  2. 【转】OPenGL MFC绘图

    一.简介 GDI是通过设备句柄(Device Context以下简称"DC")来绘图,而OpenGL则需要绘制环境(Rendering Context,以下简称"RC&q ...

  3. sdi 采集卡---环视频拼接直播方案

    http://www.upano.cn/# 360度无死角直播1080p 30fps http://search.jd.com/Search?keyword=sdi%E9%87%87%E9%9B%86 ...

  4. par函数的ann 参数-控制图片的注释信息

    ann 参数控制图片的x轴和y轴标签以及标题是否显示 默认值为TRUE, 所以图片有对应的信息时,会显示出来,代码示例 plot(1:5, 1:5, main = "title", ...

  5. dom元素改变监听

    function domChange(domId, callback) { // select the target node var target = document.getElementById ...

  6. 解决error: Your local changes to the following files would be overwritten by merge

    在项目里我们一般都会把自己第一次提交的配置文件忽略本地跟踪 1 [Sun@webserver2 demo]$ git update-index --assume-unchanged <filen ...

  7. [dubbo] dubbo No provider available for the service

    com.alibaba.dubbo.rpc.RpcException: Failed to invoke the method queryTemplate in the service com.x.a ...

  8. Oracle会话及连接数优化

    一.改动Oracle会话及最大连接数 1.查看最大连接数 SQL> show parameter processes; NAME                                 ...

  9. ios 调用系统应用的方法 应用间跳转的方法

    声明一个私有方法: #pragma mark - 私有方法 -(void)openUrl:(NSString *)urlStr{ //注意url中包含协议名称,iOS根据协议确定调用哪个应用,例如发送 ...

  10. Python Scrapy初步使用

    1.创建爬虫工程 scrapy startproject stockproject001 2.创建爬虫项目 cd stockproject001 scrapy genspider stockinfo ...