做法:注意行和列能整除p的情况,然后分块构造。赛场上写的太难看,码力不够QAQ
AC代码:
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb(x) push_back(x)
#define sz(x) (int)(x).size()
#define sc(x) scanf("%d",&x)
#define pr(x) printf("%d\n",x)
#define abs(x) ((x)<0 ? -(x) : x)
#define all(x) x.begin(),x.end()
#define mk(x,y) make_pair(x,y)
#define debug printf("!!!!!!\n")
#define fin freopen("in.txt","r",stdin)
#define fout freopen("out.txt","w",stdout)
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 1e9+7;
const double PI = 4*atan(1.0);
const int maxm = 1e8+5;
const int maxn = 1e6+5;
const int INF = 0x3f3f3f3f;
int mp[105][105];
int main()
{
//fin;
IO;
int n,m,p;
cin>>n>>m>>p;
int t = n*m;
if(t%p!=0) cout<<"No"<<endl;
else{
if(p>n && p>m){
cout<<"No"<<endl;
return 0;
}
int x = t/p;
if(x<=t)
{
cout<<"Yes"<<endl;
if(n%p == 0)
{
int pos = 1;
for(int k=0;k<n/p;k++)
{
for(int i=0;i<p;i++)
{
for(int j=0;j<m;j++)
{
cout<<j+pos<<" ";
}
cout<<endl;
}
pos+=m;
}
}
else
{
int pos = 1;
int tmp = 0;
for(int k=0;k<m/p;k++)
{
for(int i=0;i<p;i++)
{
for(int j=0;j<n;j++)
{
mp[i+tmp][j] = pos+j;
}
}
pos+=n;
tmp+=p;
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<mp[j][i]<<" ";
cout<<endl;
}
}
}
else cout<<"No"<<endl;
}
return 0;
}