前言
对着样例构造乱搞过了QAQ
题意
构造一个n*m的矩阵,每个元素在-1e9~1e9间,每一个大小为h*w的子矩阵和是负数,而整个矩阵的和是正数。
构造
如果n是h的倍数且m是w的倍数,那么整个矩阵恰好分成若干个h*w的子矩阵,既然每个都是负数,和怎么可能是正数?
然后我们可以设一个d(d是常数比4000小就行然后尽量大比如2000),对于一个(ih,jw),我们填上-(hw-1)d-1,其余位置填上d。
这样每一个大小为h*w的子矩阵和一定是-1。
而因为有多余行列,只要有多余的一行或一列就能把这些-1拯救回来,整个矩阵和为正数。
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=500+10;
int a[maxn][maxn];
int i,j,k,l,t,n,m,d,h,w;
int main(){
scanf("%d%d%d%d",&n,&m,&h,&w);
d=2000;
fo(i,1,n)
fo(j,1,m)
a[i][j]=d;
fo(i,1,n/h)
fo(j,1,m/w)
a[h*i][w*j]=-(h*w-1)*d-1;
t=0;
fo(i,1,n)
fo(j,1,m)
t+=a[i][j];
if (t<=0){
printf("No\n");
return 0;
}
printf("Yes\n");
fo(i,1,n){
fo(j,1,m) printf("%d%c",a[i][j],j==m?'\n':' ');
}
}