【BZOJ5136】【LOJ6256】【CodePlus 2017 12 月赛】可做题1 & LibreOJ6256
2017-12-24 15:44
387 查看
Description
click meSolution
可以证明每个矩阵是巧妙的当且仅当其每个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; } //秦中花鸟已应阑,塞外风沙犹自寒。 // -- 王翰《凉州词二首》
相关文章推荐
- [最短路][DP][传递闭包] BZOJ 5109 && LOJ #6252. 「CodePlus 2017 11 月赛」大吉大利,晚上吃鸡!
- 【loj6257】「CodePlus 2017 12 月赛」可做题2
- LOJ #6256. 「CodePlus 2017 12 月赛」可做题1
- 【LIbreOJ】#6256. 「CodePlus 2017 12 月赛」可做题1
- 【LibreOJ】#6257. 「CodePlus 2017 12 月赛」可做题2
- 「CodePlus 2017 12 月赛」可做题2(矩阵快速幂+exgcd+二分)
- [二分] bzoj5106: [CodePlus2017]汀博尔 & loj#6249. 「CodePlus 2017 11 月赛」汀博尔
- [计数][容斥] LOJ#6065 || BZOJ4927 && 2017 山东一轮集训 Day3. 第一题
- [LOJ6259][CodePlus 2017 12 月赛]白金元首与独舞-矩阵树定理
- CodePlus 2017 12 月赛 可做题2 矩阵乘法+exgcd
- BZOJ 4017&&2017 icpc 西安G 区间异或和
- BZOJ4898 & BZOJ5367 & 洛谷3778:[APIO2017]商旅——题解
- 「CodePlus 2017 12 月赛」火锅盛宴
- 走进矩阵树定理--「CodePlus 2017 12 月赛」白金元首与独舞
- 「CodePlus 2017 11 月赛」可做题
- BZOJ 4017&&2017 icpc 西安G 区间异或和
- 洛谷 P4032 「CodePlus 2017 12 月赛」火锅盛宴(splay+堆)
- BZOJ:4820: [Sdoi2017]硬币游戏&&BZOJ:1444: [Jsoi2009]有趣的游戏(高斯消元求概率)
- BZOJ 4017&&2017 icpc 西安G 区间异或和
- [bzoj4822][Cqoi2017]老C的任务&[bzoj1935][Shoi2007]Tree 园丁的烦恼