ZOJ 3212 K-Nice(满足某个要求的矩阵构造)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu
Description
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
构造出一个含有k个nice点的n*m的矩阵
nice点:周围四个数字之和等于该数字
不在边缘和角处构造
这样简单一点
先全部初始化-1
0的点其周围4个全为0
这样构造
#include<cstdio>
#include<string>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<cstring>
#include<set>
#include<queue>
#include<algorithm>
#include<vector>
#include<map>
#include<cctype>
#include<stack>
#include<sstream>
#include<list>
#include<assert.h>
#include<bitset>
#include<numeric>
#define eps 10e-6
#define INF 999999999
#define max_v 25
int a[max_v][max_v];
using namespace std;
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,k;
scanf("%d %d %d",&n,&m,&k);
memset(a,-,sizeof(a));
for(int i=;i<n-;i++)
{
for(int j=;j<m-;j++)
{
if(k<=)
break;
if(a[i][j]<=)
{
k--;
a[i][j]=;
a[i+][j]=;
a[i-][j]=;
a[i][j+]=;
a[i][j-]=;
}
}
if(k<=)
break;
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(a[i][j]<)
a[i][j]=;
}
}
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(j==)
printf("%d",a[i][j]);
else
printf(" %d",a[i][j]);
}
printf("\n");
}
}
return ;
}
/* 题目意思:
构造出一个含有k个nice点的n*m的矩阵
nice点:周围四个数字之和等于该数字 分析:
不在边缘和角处构造
这样简单一点
先全部初始化-1
0的点其周围4个全为0
这样构造 之和将等于-1的点替换成1 这样就是构造完毕 */
ZOJ 3212 K-Nice(满足某个要求的矩阵构造)的更多相关文章
- 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 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倍动态减法游戏,难度较大,参看了好多资料才懵懂! 此题可 ...
- poj 3613 经过k条边最短路 floyd+矩阵快速幂
http://poj.org/problem?id=3613 s->t上经过k条边的最短路 先把1000范围的点离散化到200中,然后使用最短路可以使用floyd,由于求的是经过k条路的最短路, ...
- ZOJ 3256 Tour in the Castle 插头DP 矩阵乘法
题解 这题是一道非常好的插头题,与一般的按格转移的题目不同,由于m很大,要矩阵乘法,这题需要你做一个按列转移的插头DP. 按列转移多少与按格转移不同,但大体上还是基于连通性进行转移.每一列只有右插头是 ...
- numpy.ones_like(a, dtype=None, order='K', subok=True)返回和原矩阵一样形状的1矩阵
Return an array of ones with the same shape and type as a given array. Parameters: a : array_like Th ...
- ZOJ - 2671 Cryptography(线段树+求区间矩阵乘积)
题意:已知n个矩阵(下标从1开始),求下标x~y区间矩阵的乘积.最多m次询问,n ( 1 <= n <= 30,000) and m ( 1 <= m <= 30,000). ...
- 机器学习PR:k近邻法分类
k近邻法是一种基本分类与回归方法.本章只讨论k近邻分类,回归方法将在随后专题中进行. 它可以进行多类分类,分类时根据在样本集合中其k个最近邻点的类别,通过多数表决等方式进行预测,因此不具有显式的学习过 ...
随机推荐
- .NET中的异步编程
开篇 异步编程是程序设计的重点也是难点,还记得在刚开始接触.net的时候,看的是一本c#的Winform实例教程,上面大部分都是教我们如何使用Winform的控件以及操作数据库的实例,那时候做的基本都 ...
- css points
<style type="text/css" rel="stylesheet">.a{ width:500px; height:400px;对放置图 ...
- Laravel 多域名共享session
在网站开发中会涉及登陆的问题,在登陆的过程中为了方便用户体验,我们需要用户在主域名登陆,在其他域名下也要保持登陆状态: 在config/session.php中: 更新网站配置缓存即可
- unrecognized selector sent to class
Other Linker Flags=-ObjC -all_load Loads all members of static archive libraries. -ObjC Loads all me ...
- Android设备网络、屏幕尺寸、SD卡、本地IP、存储空间等信息获取工具类
Android设备网络.屏幕尺寸.SD卡.本地IP.存储空间.服务.进程.应用包名等信息获取的整合工具类. package com.qiyu.ddb.util; import android.anno ...
- RxJava + Retrofit完成网络请求
1.前言 本文基于RxJava.Retrofit的使用,若是对RxJava或Retrofit还不了解的简友可以先了解RxJava.Retrofit的用法再来看这篇文章. 在这片文章之前分别单独介绍过R ...
- GridView视图(BaseAdapter)
效果图:
- 【AOP】spring 的AOP编程报错:[Xlint:invalidAbsoluteTypeName]error
AOP来发过程中,报错如下: warning no match for this type name: net.shopxx.wx.institution.controller [Xlint:inva ...
- MySQL 5.7.24 privileges有哪些?
root@localhost:3306.sock [mysql]>select version();+------------+| version() |+------------+| 5.7 ...
- REST Framework 的分页
分页: PageNumberPagination from rest_framework.pagination import PageNumberPagination 导入分页之后你要实例化分页这个对 ...