ECNU 2018 October Month race E cover House (Bitset + multiply)

Source: Internet
Author: User
Tags bitset

Topic link ECNU Monthly 2018.10 problem E

From the opening to the end ...

It is obvious to divide the triangle into two parts.

Divide each part into three parts, the above part as an example.

Above and to the right, and the lower left corner of the square.

That is, two small triangles and a square together.

It's a bit of a hassle when dealing with squares.

Then multiply it directly.

#include <bits/stdc++.h>using namespace std; #define REP (I, A, b) for (int i (a); I <= (b); ++i) #definedec (i, A, b) f or (int i (a); I >= (b); i) #definefifirst #definesesecond#definempmake_pairtypedef long long ll;const int N = 1e3 + 10; Bitset <102> f[n][n][10], g[n][n][10], ff[n][n][10], Gg[n][n][10];int N, M, q;int t;int lg[n + 10];inline int Check ( int x, int y) {return x >= 1 && x <= n && y >= 1 && y <= m;} int main () {lg[1] = 0;rep (i, 2, 1001) lg[i] = lg[i >> 1] + 1;scanf ("%d%d", &n, &m); Rep (i, 1, N) {rep (J, 1, m) { int x;scanf ("%d", &x); F[i][j][0].set (x); G[i][j][0].set (x); Ff[i][j][0].set (x); Gg[i][j][0].set (x);}} Rep (k, 1, 9) {Rep (i, 1, N) {rep (J, 1, m) {int xx, yy, zz = 1 << (k-1); F[i][j][k] |= f[i][j][k-1];xx = I-zz;yy = J  if (check (xx, yy)) f[i][j][k] |= f[xx][yy][k-1];xx = I;yy = j + zz;if (check (xx, yy)) F[i][j][k] |= f[xx][yy][k-1];xx = I-zz;yy = j + zz;if (check (xx, yy)) f[i][j][k] |= f[xx][yy][k-1]; Ff[i][j][k] |= ff[i][j][k-1];xx = i + zz;yy = j;if (check (xx, yy)) ff[i][j][k] |= ff[xx][yy][k-1]; xx = I;yy = j + zz;if (check (xx, yy)) ff[i][j][k] |= ff[xx][yy][k-1];xx = i + zz;yy = j + zz;if (check (xx, yy)) FF I [j]                [K] |= ff[xx][yy][k-1]; }}}rep (k, 1, 9) {Rep (i, 1, N) {rep (J, 1, m) {int xx, yy, zz = 1 << (k-1); G[i][j][k] |= f[i][j][k-1];xx = i-zz;yy = J;if (check (xx, yy)) g[i][j][k] |= g[xx][yy][k-1];xx = I;yy = j + zz;if (check (xx, yy)) g[i][j][k] |= g[xx][yy][k-1] ; Gg[i][j][k] |= ff[i][j][k-1];xx = i + zz;yy = j;if (check (xx, yy)) gg[i][j][k] |= gg[xx][yy][k-1];xx = I;yy = j + zz; if (check (xx, yy)) gg[i][j][k] |= gg[xx][yy][k-1];}} scanf ("%d", &q), while (q--) {int x, Y, z;scanf ("%d%d%d", &x, &y, &z), if (z = = 1) {puts ("1"); continue;} int c = Lg[z];bitset <102> ret;int xx, yy, zz = 1 << c;xx = x-z + zz;yy = Y;ret |= g[xx][yy][c];xx = X;yy = Y + z-zz;ret |= g[xx][yy][c];int t = (z) >> 1;int L = lg[t], LL = 1 << l;ret |= f[x][y][l];xx = x-t + ll;yy = Y;ret |= f[xx][yy][l];xx = X;yy = y + t-ll;re T |= f[xx][yy][l];xx = x-t + ll;yy = y + t-ll;ret |= f[xx][yy][l];xx = x + z-zz;yy = y;ret |= gg[xx][yy][c];xx = x;y y = y + z-zz;ret |= gg[xx][yy][c];ret |= ff[x][y][l];xx = x + t-ll;yy = y;ret |= ff[xx][yy][l];xx = X;yy = y + t-ll; RET |= ff[xx][yy][l];xx = x + t-ll;yy = y + t-ll;ret |= ff[xx][yy][l];p rintf ("%d\n", (int) ret.count ());} return 0;}

ECNU 2018 October Month race E cover House (Bitset + multiply)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.