Zoj 3212 K-Nice (k)

Source: Internet
Author: User
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 ifKOf the elements inside the matrix are "nice ".

Now given the size of the matrix and the valueK, You are to output any one of"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 integerT(1 <=T<= 8500) followedTTest Cases. Each case contains three IntegersN,M,K(2 <=N,M<= 15, 0 <=K<= (N-2 )*(M-2) indicating the matrix sizeN*MAnd it the "nice"-degreeK.

Output

For each test case, output a matrixNLines each containingMElements separated by a space (no extra space at the end of the line). The absolute value of the elements in the matrix shocould not be greater than 10000.

Sample Input

 

24 5 35 5 3

 

Sample output

 

2 1 3 1 14 8 2 6 11 1 9 2 92 2 4 30 1 2 3 00 4 5 6 00 0 0 00 0 0 0 00 0 0 0 0 0 0 0 0 0

Ideas:
Because if the requirement has K satisfied, then the other is 0, as long as the fill (n-2) * (m-2)-K individual number can meet.
 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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.