由于博主没有BZOJ权限号, 是在洛咕做的题~

 

完成了13题(虽然有一半难题都是看题解的QAQ)剩下的题咕咕咕~~

Luogu3585 [POI2015]PIE

Solution

模拟, 按顺序搜索, 把搜索到的需要印却没有印的点 和 印章的第一个点重合, 并印上。

另外, 纸上需要印的点 和 印章上沾墨水的点用数组储存, 能加快很多

Code

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<vector>
 5 #define R register
 6 using namespace std;
 7 typedef pair<int, int> P;
 8 
 9 const int N = 1e3 + 5;
10 
11 int n, m, a, b;
12 int stx, sty;
13 char s[N], in[N][N], mp[N][N];
14 
15 vector<P> need, offer;
16 
17 int jud(int x, int y) {
18     if (x <= 0 || y <= 0 || x > n || y > m)
19         return 0;
20     return 1;
21 }
22 
23 #define X first
24 #define Y second
25 int col(int x, int y) {
26     for (R int i = 0, up = offer.size(); i < up; ++i) {
27         int onx = x + offer[i].X - stx, ony = y + offer[i].Y - sty;
28         if (!jud(onx, ony)) return 0;
29         if (mp[onx][ony] == '.') return 0;
30         mp[onx][ony] = '.';
31     }
32     return 1;
33 }
34 
35 int work() {
36     stx = sty = 0;
37     offer.clear(); need.clear();
38     for (R int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
39     for (R int i = 1; i <= a; ++i) scanf("%s", in[i] + 1);
40     for (R int i = 1; i <= n; ++i)
41         for (R int j = 1; j <= m; ++j) if (mp[i][j] == 'x')
42             need.push_back(P(i, j));
43     for (R int i = 1; i <= a; ++i)
44         for (R int j = 1; j <= b; ++j) if (in[i][j] == 'x') {
45             offer.push_back(P(i, j));
46             if (!stx) stx = i, sty = j;
47         }
48     
49     for (int i = 0, up = need.size(); i < up; ++i)
50         if (mp[need[i].X][need[i].Y] == 'x')
51             if (!col(need[i].X, need[i].Y)) return 0;
52     return 1;
53 }
54 #undef X
55 #undef Y
56 
57 int main()
58 {
59     int Q; scanf("%d", &Q);
60     for (; Q; Q--) {
61         scanf("%d%d%d%d", &n, &m, &a, &b);
62         if (work()) puts("TAK");
63         else puts("NIE");
64     }
65 }
Luogu3585 PIE

相关文章:

  • 2021-08-09
  • 2021-05-19
  • 2021-09-16
  • 2021-06-17
  • 2021-11-07
  • 2021-09-09
  • 2021-12-08
  • 2021-12-27
猜你喜欢
  • 2021-10-09
  • 2022-02-13
  • 2021-09-23
  • 2021-12-31
相关资源
相似解决方案