ZOJ 3212 K-Nice (K)

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

思路:因为如果要求有K个满足,那么别的都是0,只要填入(n-2)*(m-2)-k个别的数即可满足。
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <string>
 5 using namespace std;
 6 int T, n, m, k;
 7 #define maxn 20
 8 int a[maxn][maxn];
 9 int main(){
10     scanf("%d", &T);
11     while(T--){
12         scanf("%d%d%d", &n, &m, &k);
13         k = (n-2)*(m-2)-k;
14         for(int i = 1; i <= n; i++){
15             printf("0");
16             for(int j = 2; j <= m-1; j++){
17                 if(k == 0) printf(" 0");
18                 else printf(" %d", k--);
19             }printf(" 0\n");
20         }
21
22
23     }
24
25     return 0;
26 }

ZOJ 3212 K-Nice (K),布布扣,bubuko.com

时间: 2025-01-02 18:29:17

ZOJ 3212 K-Nice (K)的相关文章

1^k+2^k+3^k+&#183;&#183;&#183; ZOJ 3547 UVA 766

题目链接:点击打开链接 祭出结论:点击打开链接 资料:组合数回代公式:点击打开链接 伯努利数:点击打开链接 点击打开链接 方法一: 首先给出一个神奇的组合数公式: C(n,k)+C(n+1,k)+C(n+2,k)+C(n+3,k)--+C(N,k) 由于: C(n,k)=C(n-1,k)+C(n-1,k-1) 因此 上式  =  - C(n,k+1) +  {  C(n,k+1)+C(n,k)   }  +  C(n+1,k)-- =  - C(n,k+1) +  {C(n+1,k+1}  + 

UVA 1363 Joseph&#39;s Problem 找规律+推导 给定n,k;求k%[1,n]的和。

/** 题目:Joseph's Problem 链接:https://vjudge.net/problem/UVA-1363 题意:给定n,k;求k%[1,n]的和. 思路: 没想出来,看了lrj的想法才明白. 我一开始往素数筛那种类似做法想. 想k%[1,n]的结果会有很多重复的,来想办法优化. 但没走通. 果然要往深处想. 通过观察数据发现有等差数列.直接观察很难确定具体规律:此处应该想到用式子往这个方向推导试一试. lrj想法: 设:p = k/i; 则:k%i = k-i*p; 容易想到

判断字符串是否包含字母‘k’或者‘K’

判断字符串是否包含字母‘k’或者‘K’ public bool IsIncludeK(string temp) { temp = temp.ToLower(); if (temp.Contains('k')) { return true; } else { return false; } }

ZOJ 3774 Fibonacci的K次方和

In mathematics, Fibonacci numbers or Fibonacci series or Fibonacci sequence are the numbers of the following integer sequence: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ... By definition, the first two numbers in the Fibonacci sequence are

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 on

设计一个算法,求非空二叉树中指定的第k层(k&gt;1)的叶子节点的个数

思想:采用基于层序遍历的方法.用level扫描各层节点,若某一层的节点出队后,rear指向该层中最右节点,则将rear赋值给last(对于第一层,last=1).在出队时,若front=last,表示这一层处理完毕,让层号level增1,并置last为下一层最右节点.那么如何求一层的最右节点呢?这是因为第一层只有一个节点,它就是最右节点.对于其他层,上一层最右节点最后进队的孩子一定是该层的最右节点. 例如,对于如图所示的二叉树,求k=3的叶子节点个数的过程如下:level=1;A进队时rear=

ZOJ 3212: K-Nice

K-Nice ///@author Sycamore, ZJNU ///@date 2017-02-09  #include<iostream> #include<algorithm> using namespace std; int mat[15][15]; int main() { int T, M, N, k; cin >> T; while (T--) { cin >> N >> M >> k; fill(*(mat + 1)

最短路 次短路 k短路(k很小)

最短路 luogu 3371 https://www.luogu.org/problemnew/show/P3371 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cstring> 4 #include <queue> 5 #include <algorithm> 6 using namespace std; 7 const int maxn=1e4+10; 8 9 int dist[m

给定一个正整数k(3≤k≤15),把所有k的方幂及所有有限个互不相等的k的方幂之和构成一个递增的序列,例如,当k=3时,这个序列是: 1,3,4,9,10,12,13,… (该序列实际上就是:3^0,3^1,3^0+3^1,3^2,3^0+3^2,3^1+3^2,3^0+3^1+3^2,…) 请你求出这个序列的第N项的值(用10进制数表示)。 例如,对于k=3,N=100,正确答案应该是9

只有1行,为2个正整数,用一个空格隔开: k N (k.N的含义与上述的问题描述一致,且3≤k≤15,10≤N≤1000). 计算结果,是一个正整数(在所有的测试数据中,结果均不超过2.1*10^9).(整数前不要有空格和其他符号). #include<stdio.h> int n2[1010];long long l1 = 1; long long n, k; long long sm(long long i,long long k) { long long s = 1; int j; fo