ZOJ 3212 K-Nice
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 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
#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的更多相关文章
- ZOJ 3212 K-Nice(满足某个要求的矩阵构造)
H - K-Nice Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Sta ...
- 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 3599 K倍动态减法游戏
下面的文字辅助理解来自http://blog.csdn.net/tbl_123/article/details/24884861 博弈论中的 K倍动态减法游戏,难度较大,参看了好多资料才懵懂! 此题可 ...
- django模型操作
Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表
- ZOJ 2112 Dynamic Rankings(动态区间第 k 大+块状链表)
题目大意 给定一个数列,编号从 1 到 n,现在有 m 个操作,操作分两类: 1. 修改数列中某个位置的数的值为 val 2. 询问 [L, R] 这个区间中第 k 大的是多少 n<=50,00 ...
- ZOJ 2112 Dynamic Rankings (动态第 K 大)(树状数组套主席树)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- ZOJ 2112 Dynamic Rankings(带修改的区间第K大,分块+二分搜索+二分答案)
Dynamic Rankings Time Limit: 10 Seconds Memory Limit: 32768 KB The Company Dynamic Rankings has ...
- ZOJ -2112 Dynamic Rankings 主席树 待修改的区间第K大
Dynamic Rankings 带修改的区间第K大其实就是先和静态区间第K大的操作一样.先建立一颗主席树, 然后再在树状数组的每一个节点开线段树(其实也是主席树,共用节点), 每次修改的时候都按照树 ...
随机推荐
- repo manifest.xml 分析
repo是用于管理android的git仓库的工具. 之前想将android的代码放在github上面,并通过repo进行管理.但一直不知道怎么添加进去,那么多的git仓库,难道都要手动建立吗? 直到 ...
- if、for、while、do 等语句自占一行
if.for.while.do 等语句自占一行,执行语句不得紧跟其后.不论 执行语句有多少都要加{}.这样可以防止书写失误. #include <iostream> /* run this ...
- 【Java面试题】31 介绍Collection框架的结构
Collection:List列表,Set集 Map:Hashtable,HashMap,TreeMap Collection 是单列集合 List 元素是有序的.可重复 有序的 colle ...
- php字符串算术表达式计算
$aa = "{1}*{2}-{3}"; $farr = array('/\{1\}/','/\{2\}/','/\{3\}/'); $tarr = array(3,4,10); ...
- Ubuntu Server 下的网络配置
$ ifconfig 配置DHCP客户端$ sudo vi /etc/network/interfaces加入 iface eth0 inet dhcp 配置静态IP地址$ sudo vi /etc/ ...
- 视觉SLAM之词袋(bag of words) 模型与K-means聚类算法浅析(1)
在目前实际的视觉SLAM中,闭环检测多采用DBOW2模型https://github.com/dorian3d/DBoW2,而bag of words 又运用了数据挖掘的K-means聚类算法,笔者只 ...
- 发布订阅者模式之C#委托实现
1 ...
- C# 温故而知新:Stream篇(二)
TextReader 和StreamReader 目录: 为什么要介绍 TextReader? TextReader的常用属性和方法 TextReader 示例 从StreamReader想到多态 简 ...
- sqlite数据库下载安装和初步操作和所遇到的问题near "sqlite3":syntax error
1.下载sqlite数据库:http://www.sqlite.org/download.html 假设是在window上安装须要在 Windows 区下载预编译的二进制文件.如图下载下载 sqlit ...
- swift学习笔记之--方法
一.说明 跟oc一样,面向对象,swift重点额方法可以分为2大类: (1)实例方法 oc中为减号方法(对象方法) (2)类型方法 oc中的加号方法(类方法) 二.实例方法 只能是对象调用的方法 代码 ...