您的位置:首页 > 其它

【BZOJ5136】【LOJ6256】【CodePlus 2017 12 月赛】可做题1 & LibreOJ6256

2017-12-24 15:44 387 查看

Description

click me

Solution

可以证明每个矩阵是巧妙的当且仅当其每个2阶子矩阵均是巧妙的:

若该矩阵有一个不巧妙的2阶子矩阵,则其他部分任意选择,这两行选择不同,则和不同,所以该矩阵不是巧妙的。

用goodi,jgoodi,j表示以(i,j)(i,j)为左上角的二阶子矩阵是否巧妙,计算前缀和即可。

Code

/**************************
Au: Hany01
Date: Dec 24th, 2017
Prob: Code+ Round2 Div2 T2
Email: hany01@foxmail.com
**************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
#define rep(i, j) for (register int i = 0, i##_end_ = (j); i < i##_end_; ++ i)
#define For(i, j, k) for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++ i)
#define Fordown(i, j, k) for (register int i = (j), i##_end_ = (k); i >= i##_end_; -- i)
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define fir first
#define sec second
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Ha (1000000007)

template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read()
{
int _, __; char c_;
for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar()) if (c_ == '-') __ = -1;
for ( ; c_ >= '0' && c_ <= '9'; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
return _ * __;
}

inline void File()
{
#ifdef hany01
freopen("solve1.in", "r", stdin);
freopen("solve1.out", "w", stdout);
#endif
}

const int maxn = 505;

int n, m, T, a[maxn][maxn], good[maxn][maxn], x, y, k;

int main()
{
File();
n = read(); m = read(); T = read();
For(i, 1, n) For(j, 1, m) a[i][j] = read();
For(i, 1, n - 1) For(j, 1, m - 1)
good[i][j] = good[i - 1][j] + good[i][j - 1] - good[i - 1][j - 1] + (a[i][j] + a[i + 1][j + 1] == a[i + 1][j] + a[i][j + 1]);
while (T --) {
x = read(); y = read(); k = read();
if (good[x + k - 2][y + k - 2] - good[x - 1][y + k - 2] - good[x + k - 2][y - 1] + good[x - 1][y - 1] == (k - 1) * (k - 1))
puts("Y");
else puts("N");
}
return 0;
}
//秦中花鸟已应阑,塞外风沙犹自寒。
//    -- 王翰《凉州词二首》
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: