「SWTR-07」Scores(easy version)

洛谷题面

来一发题解。

题目大意

给定 \(n,m\),请构造一个 \(n\times m\) 的矩阵 \(\rm Mat\),矩阵的所有元素范围均为 \([0,100]\) 之间的整数,且对于任意 \(i,j(i\neq j)\) 存在一个 \(k\) 使得 \(\rm Mat_{i,k}>Mat_{j,k}\)

如果存在输出 \(\texttt{yes}\),否则输出 \(\texttt{no}\)

题目分析

既然有 \(\rm Special~Judge\),那么我们可以随便构造,只要符合条件就行。

  • 对于输出 \(\texttt{yes}\) 的情况。

考虑到对于矩阵 \(\rm Mat\),我们一定要保证 \(\rm Mat_{i,k}>Mat_{j,k}\),那么我们一行中一定要有大的,也一定要有比较小的,那么可以这样来构造:


\(\color{black}\tiny{Image~courtesy~of~a~certain~person}\)

换句话说就是构造 \(\rm Mat = \begin{Bmatrix}1&100-1& 100-1&...&100-1 \\...\\n&100-n&100-n&...&100-n\end{Bmatrix}\)

直接构造就好啦。

  • 对于输出 \(\texttt{no}\) 的情况。

特判 \(m=1\)\(n>1\) 时。

代码

//2021/9/21

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <cstdio>

#define debug(c) cerr<<#c<<" = "<<c<<endl

#define cek(c) puts(c)

namespace Newstd
{
	inline int read()
	{
		char c;
		bool flag=false;
		while((c=getchar())<'0' || c>'9')
		{
		    if(c=='-') flag=true;
		}
		int res=c-'0';
		while((c=getchar())>='0' && c<='9')
		{
		    res=(res<<3)+(res<<1)+c-'0';
		}
		return flag?-res:res;
	}
	inline void print(int x)
	{
		if(x<0)
		{
			putchar('-');x=-x;
		}
		if(x>9)
		{
			print(x/10);
		}
		putchar(x%10+'0');
	}
}

using namespace Newstd;

using namespace std;

const int ma=105;

int mp[ma][ma];

int main(void)
{
	int kase=read(),T=read();
	
	while(T--)
	{
		int n=read(),m=read();
		
		if(m==1 && n>1)
		{
			puts("NO");
			
			continue;
		}
		
		for(register int i=1;i<=n;i++)
		{
			mp[i][1]=i;
			
			for(register int j=2;j<=m;j++)
			{
				mp[i][j]=n-i;
			}
		}
		
		puts("YES");
		
		for(register int i=1;i<=n;i++)
		{
			for(register int j=1;j<=m;j++)
			{
				printf("%d ",mp[i][j]);
			}
			
			printf("\n");
		}
	}
	
	return 0;
}
posted @ 2021-09-24 22:41  Coros_Trusds  阅读(69)  评论(0)    收藏  举报