【ZOJ - 3212 】K-Nice (构造)

题干:

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 Ttest 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

题目大意:

构造出一个含k个nice的n*m的矩阵。nice:周围4个数字之和等于该数字(边缘的数字不属于,因为周围没有4个数字)。

解题报告:

  第一个样例一点提示性都没有,但是看到第二个样例就明白了,可以全填0,这样是构造了一个满k的矩阵,然后再依次填数就可以了。填一个数,k就变小了1.

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
const int MAX = 200 + 5;
int a[MAX][MAX];
int main()
{int t;cin>>t;while(t--) {int m,n,k;scanf("%d%d%d",&n,&m,&k);memset(a,0,sizeof a);k = (n-2)*(m-2) - k;int cur = 0;for(int i = 1; i<=n; i++) {for(int j = 2; j<=m-1; j++) {if(cur < k) a[i][j] = ++cur;}}for(int i = 1; i<=n; i++) {for(int j = 1; j<=m; j++) {printf("%d%c",a[i][j],j == m ? '\n' : ' ');}}}return 0 ;
}

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/440633.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

chrome jsp 显示不正常_JSP程序在chrome下不兼容的问题!

比如&#xff0c;我这里有个&#xff1a;">比如&#xff0c;我这里有个&#xff1a;οnclick"javascript:onChooseLongCode()" value"...">在下面的JS动作中&#xff1a;function onChooseLongCode(){var qryFldVal qryFld.value;//要用 var q…

人脑意识转入量子计算机,人脑产生意识:可能是因为量子纠缠

图片来源&#xff1a;quanta magazine一提到“量子意识”这个词语&#xff0c;大多数物理学家都会选择避而不谈&#xff0c;因为这个词语听起来好像有点“民科”&#xff0c;甚至让人联想宗教或者玄学。不过出人意料的是&#xff0c;量子效应可能真的在人类的认知过程中起到了一…

【ZOJ - 1163】The Staircases(dp)

题干&#xff1a; One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Ev…

函授本科统考计算机考试时间,函授2006级计算机、机电本科第一学期考试时间安排.doc...

函授2006级计算机、机电本科第一学期考试时间安排.doc函授2006级计算机、机电本科第一学期考试时间安排答疑时间9月16日下午2&#xff1a;30&#xff0d;3&#xff1a;309月16日下午3&#xff1a;30&#xff0d;4&#xff1a;309月16日下午4&#xff1a;30&#xff0d;5&#x…

的级联选择_级联接收机的计算及Y因子噪声因子测量法

对于RF系统工程师来说&#xff0c;计算噪声系数预算对预测产品性能至关重要。一、级联接收机的计算这部分讨论噪声系数的一般概念&#xff0c;以及产品定义和电路设计者如何利用噪声系数表示噪声性能要求。噪声系数也用于预测接收机系统的总体灵敏度。也介绍级联接收机的噪声系…

*【PAT天梯】分而治之(并查集,暴力)

题干&#xff1a; L2-1 分而治之 &#xff08;25 分&#xff09; 分而治之&#xff0c;各个击破是兵家常用的策略之一。在战争中&#xff0c;我们希望首先攻下敌方的部分城市&#xff0c;使其剩余的城市变成孤立无援&#xff0c;然后再分头各个击破。为此参谋部提供了若干打击…

免费测试英语发音的软件,2020英语音标免费版

2020英语音标免费版是一款安卓手机英语音标内容学习软件&#xff0c;在这里汇集了英语音标相关内容学习&#xff0c;包含了音标、发音等内容学习&#xff0c;能够进行对比练习&#xff0c;不断对比&#xff0c;让发音更标准&#xff0c;拥有详细的发音知识可以学习&#xff0c;…

ajax后台重定向会返回什么_跳转,AJAX返回和重定向

## 页面跳转操作完成后,成功或失败页面跳转可以使用 控制器基类的success,error方法:#### success方法php/*** 操作成功跳转的快捷方法* access protected* param mixed $msg 提示信息* param string $url 跳转的URL地址* param mixed $data 返回的数据* param integer $wait 跳…

【PAT天梯】【L2-2 小字辈(左子右兄加强版)】(树,水题)

题干&#xff1a; L2-2 小字辈&#xff08;左子右兄加强版&#xff09; &#xff08;25 分&#xff09; 本题给定一个庞大家族的家谱&#xff0c;要请你给出最小一辈的名单。 需要注意的是&#xff0c;家族成员的输入方式&#xff0c;是按照“Left-child Right-sibling”&…

W10的服务器正在运行,win10开机提示服务器正在运行中的解决教程

今天小编给大家分享的是win10开机提示服务器正在运行中的解决教程。最近有win10的用户反映&#xff0c;在开机的时候莫名的就出现了个“服务器正在运行中”的气泡提示&#xff0c;出现此问题困扰的用户&#xff0c;请来看看下面的解决教程吧。使用win10系统过程中&#xff0c;在…

host ntrip 千寻rtk_最新测量干货:南方银河1和银河1Plus RTK设备连接千寻cors账号的设置方法...

无论刚接触网络RTK的测量员是想要进行华测RTK连接千寻cors账号的操作&#xff0c;还是中海达RTK连接千寻cors账号&#xff0c;亦或者司南RTK连接千寻cors账号的操作&#xff0c;我们在进行cors账号的连接操作之前都应该对操作的RTK设备有一个了解&#xff0c;所以今天我们在给大…

【CodeForces - 1084D】The Fair Nut and the Best Path (树形dp)

题干&#xff1a; The Fair Nut is going to travel to the Tree Country, in which there are nn cities. Most of the land of this country is covered by forest. Furthermore, the local road system forms a tree (connected graph without cycles). Nut wants to rent …

消息测试服务器,测试统一消息服务器功能

测试统一消息服务器功能08/07/2014本文内容适用于&#xff1a; Exchange Server 2007 SP1, Exchange Server 2007上一次修改主题&#xff1a; 2007-08-09在运行 Microsoft Exchange Server 2007 的计算机上安装统一消息服务器角色并启用和配置统一消息 (UM) 之后&#xff0c;可…

python不同曲线设置标签_【图像分类】基于Pascal VOC2012增强数据的多标签图像分类实战...

接着上一次的多标签分类综述&#xff0c;本文主要以Pascal VOC2012增强数据集进行多标签图像分类训练&#xff0c;详细介绍增强数据集制作、训练以及指标计算过程&#xff0c;并通过代码进行详细阐述&#xff0c;希望能为大家提供一定的帮助&#xff01;作者&编辑 | 郭冰洋…

【HDU - 5934】Bomb (强连通分量Tarjan + 缩点)

题干&#xff1a; There are NN bombs needing exploding. Each bomb has three attributes: exploding radius riri, position (xi,yi)(xi,yi) and lighting-cost cici which means you need to pay cici cost making it explode. If a un-lighting bomb is in or on the b…

css光线,css 射线实现方法

四种浏览器对 clientHeight、offsetHeight、scrollHeight、clientWidth、offsetWidth 和 scrollWidth 的解释差异网页可见区域宽:document.body.clientWidth 网页可见区域高:document.body.clientHeight 网页可见区域宽:document.body.offsetWid ...黄聪&#xff1a;说说JSON和…

表字段注释放在哪_橱柜台面6种材质优缺点大解剖,我来测评,告诉你哪一种适合你!...

很多人装修厨房&#xff0c;只知道橱柜要好用&#xff0c;厨房才好用。但在做橱柜的时候&#xff0c;除了橱柜的选择&#xff0c;很多装修新手还会遇到一些其他疑问&#xff1a;① 橱柜的台面用什么材质的比较好&#xff1f;② 台面的挡水条到底要不要做&#xff1f;③ 橱柜台面…

【Kattis - triangle 】Sierpiński Circumference(数学,求位数,取对数或Java)

题干&#xff1a; Polish mathematician Wacław Sierpiński (1882-1969) described the 2D geometric figure known as the Sierpiński triangle as part of his work on set theory in 1915. The triangle, which is really an infinite collection of points, can be con…

米莱狄的机器人是_王者荣耀2.22更新:米莱狄机器人化身超级兵,狂铁将成T1级战士...

王者荣耀体验服在刚刚迎来了一次小更新&#xff0c;主要针对两位海都英雄的调整&#xff0c;这也是米莱狄和狂铁自上回加强后获得的第二波BUFF&#xff0c;一起来看看这次调整能否让这两位冷门英雄成为上分首选吧&#xff01;狂铁在上回的调整中移除了大招护盾伤害和汲取能量的…

ajax post参数长度限制,Ajax中的POST数据大小是否有限制?

我想使用jQuery Ajax将我的页面中的数据数组发送到MVC Action。这里是我的jQuery代码&#xff1a;Ajax中的POST数据大小是否有限制&#xff1f;$(#btnSave).click(function() {result [];$(#tblMatters tbody tr.mattersRow).each(function() {if (!($(this).hasClass(warning…