# +/- Rectangle

## 题目描述

You are given four integers: $H, W, h$ and $w$. Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive:

• The matrix has $H$ rows and $W$ columns.
• Each element of the matrix is an integer between $-10^9$ and $10^9$ (inclusive).
• The sum of all the elements of the matrix is positive.
• The sum of all the elements within every subrectangle with $h$ rows and $w$ columns in the matrix is negative.

## 代码

#include <iostream>
using namespace std;
long long H, W, h, w, t, ans, a[501][501];
int main()
{
cin >> H >> W >> h >> w;
for (int i = 1; i <= H; ++i) {
for (int j = 1; j <= W; ++j) {
a[i][j] = 4000;
}
}
t = - h * w * 4000 + 3999;
for (int i = 0; i <= H; i += h) {
for (int j = 0; j <= W; j += w) {
a[i][j] = t;
}
}
for (int i = 1; i <= H; ++i) {
for (int j = 1; j <= W; ++j) {
ans += a[i][j];
}
}
if (ans < 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for (int i = 1; i <= H; ++i) {
for (int j = 1; j <= W; ++j) {
cout << a[i][j] << ' ';
}
cout << endl;
}
}
return 0;
}


418 I'm a teapot