【BZOJ3750】[POI2015]Pieczęć【暴力】

来源:互联网 发布:macbook air编程初学者 编辑:程序博客网 时间:2024/06/05 18:41

【题目链接】

题解:

暴力。

刻章只存x的位置,这样复杂度小点。


复杂度:

时间复杂度:O(nm*刻章里x的个数),空间复杂度:O(nm+ab)


3WA:

时间戳写挂了。


GET:

一定要注意时间戳。


/* Telekinetic Forest Guard */#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef pair<int, int> pii;const int maxn = 1005;int n, m, a, b, cnt;int g[maxn][maxn], vis[maxn][maxn], clo;pii t[maxn * maxn];inline int iread() {int f = 1, x = 0; char ch = getchar();for(; ch < '0' || ch > '9'; ch = getchar()) f = ch == '-' ? -1 : 1;for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';return f * x;}inline int cread() {char ch = getchar(); for(; ch != 'x' && ch != '.'; ch = getchar());return ch == 'x';}inline bool check() {clo++;for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(g[i][j] && vis[i][j] != clo)for(int k = 1; k <= cnt; k++) {int x = i + t[k].first, y = j + t[k].second;if(x < 1 || x > n || y < 1 || y > m) return 0;if(!g[x][y]) return 0;if(vis[x][y] == clo) return 0;vis[x][y] = clo;}return 1;}int main() {for(int T = iread(); T; T--) {n = iread(); m = iread(); a = iread(); b = iread(); cnt = 0;for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) g[i][j] = cread();for(int i = 1, x, y; i <= a; i++) for(int j = 1; j <= b; j++) if(cread()) {if(!cnt) x = i, y = j;t[++cnt] = pii(i - x, j - y);}printf(check() ? "TAK\n" : "NIE\n");}return 0;}

0 0