题解 | 球格模型(简单版)
球格模型(简单版)
https://www.nowcoder.com/practice/fada102a84ec459ea93e3db4918c0f04
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0);
int main()
{
IOS
int n, m, k;
cin>>n>>m>>k;
if(max(n, m)>k) { cout<<"-1";return 0; }
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
if(i==j)
{
if(i==1) cout<<k-max(n, m)+1;
else cout<<1;
}
else{
if(n>m && i>m && j==m) cout<<1;
else if(n<m && j>n && i==n) cout<<1;
else cout<<0;
}
cout<<" \n"[j==m];
}
}
return 0;
}
模拟,对于不是方阵的情况可以手动画一下,然后强制放到最后一行或最后一列去捏

查看30道真题和解析
