Bzoj 4558| Jloi 2016| Shoi 2016| Square | The principle of tolerance and repulsion __bzoj

Source: Internet
Author: User
Tags abs

The problem is poisonous. Poisonous poi!poi!poi!
Don't forget that the diagonal square also counts.
Don't look forward to a in the exam.
This is so much reading volume. The main effect of the topic

Statistics the number of squares that can be surrounded by a checkerboard point, some of which cannot be the vertices of a square. Solving

If there is no deletion point, the total number of scenarios is obviously ∑i=1min{n,m}i (n−i+1) (m−i+1) MODP \sum_{i=1}^{\min\{n,m\} i (n-i+1) (m-i+1) \mod p
I denotes an oblique square of I, (n-i+1) representing the number of squares (i,k) as the upper-left corner, (m-i+1) representing the number of K.

Next, consider each deleted point, which has a similar effect on the upper half, the left half, the right half, and the lower part, and the number of squares that are being counted, that is, the small value of the long width.
Use (l,r,h) (l,r,h) to represent an area, the deleted point is on the bottom boundary, the left has l coordinates, and the right has r coordinates.
Consider the area of the (6+6) *6.
There are 6 diagonal 0 lattice, 1 lattice 5, 2 lattice 4, ..., 5 lattice have 1, 6 lattice have 6, total is 27 of the two.
If it is the area of the *5 (6+6), then it is 5,4,3,2,1,5.
If it is the area of the (2+2) *5, then it is 2,2,2,2.
Make Z=min{l+r,h} z=\min\{l+r,h\}
Let's assume that the height is not greater than the left or right side, then the answer at this point is Z (z+3) 2 \frac{z (z+3)}{2}.
If it is greater than the left and right sides, consider subtracting the more calculated portions, and if the left and right sides are filled to Z, then the extra portion is n=z−l or z−r n=z-l or z-r, and the formula is N (n+1) 2 \frac{n (n+1)}{2}.

Then arbitrarily enumerate 2 points, and then you can count the number of squares that have been deleted at 2 points, 3, and 4 points, paying attention to both oblique and positive statistics.
Pay attention to the order of points, there is nothing.

#include <cstdio> #include <set> #include <algorithm> using namespace std;
typedef long Long LL;
const int N = 2005;
CONST LL mod = 1e8 + 7;
ll N, M, K;
    struct point {int x, y; Point (int a = 0, int b = 0): X (a), Y (b) {} bool operator< (const point &b) const {return x < b.x | | | x = = b.x && y < b.y; BOOL operator== (const point &b) const {return x = = b.x && y = = B.y;}}
Pt[n];
    ll nonremoved () {int k = min (n, m), I; ll ans = 0;
    for (i = 1; I <= K; ++i) (ans = (n-i + 1) * (m-i + 1)% mod * i)%= mod;
return ans;
    ll onceRemoved0 (int l, int r, int h) {int z = min (l + R, h);
    if (z = = 0) return 0;
    ll ans = Z * (z + 3)/2;
    if (Z > L) ans-= (z-l) * (z-l + 1)/2;
    if (Z > R) ans-= (z-r) * (Z-r + 1)/2;
return ans;
    ll onceremoved (int x, int y) {int t = x, b = n-x, L = y, r = m-y; Return (onceRemoved0 (t, B, L) + onceRemoved0 (T, B, R) + OnceremoveD0 (L, R, T) + onceRemoved0 (L, R, b)-min (L, t)-min (t, r)-min (R, b)-min (b, l))% MoD; BOOL Inmap (int x, int y) {return 0 <= x && x <= n && 0 <= y && y <= m;} void C Ount (Point A, point B, int &cnt2, int &cnt3, int &cnt4) {if (Inmap, a.x) && a.y (Inmap, b.x))
        {T = Mp.count (a) + Mp.count (b);
        ++cnt2;
        if (T > 0) ++cnt3;
    if (T > 1) ++cnt4, ++cnt3;
    int main () {set<point> MP;
    int I, J, R, T, x, y, dx, dy;
    scanf ("%lld%lld%lld", &n, &m, &k);
    ll ans = nonremoved ();
        for (i = 0; i < K; ++i) {scanf ("%d%d", &pt[i].x, &pt[i].y); Mp.insert (pt[i));
    (ANS-= onceremoved (pt[i].x, pt[i].y))%= mod;
    ll cnt2 = 0, Cnt3 = 0, cnt4 = 0;
        for (i = 0; i < K; ++i) {point P = pt[i];
            for (j = i + 1; j < K; ++j) {Point q = pt[j]; DX = p.x-q.x, dy = p.y-q.Y
            Count (Point (p.x + dy, p.y-dx), point (q.x + dy, q.y-dx), Cnt2, Cnt3, CNT4);
            Count (Point (p.x-dy, p.y + dx), point (q.x-dy, q.y + dx), Cnt2, Cnt3, CNT4);
            if (ABS (DX) + abs (DY)) & 1 continue;
            x = Dx-dy >> 1, y = dx + dy >> 1;
        Count (Point (P.x-x, p.y-y), point (q.x + x, Q.y + y), Cnt2, Cnt3, CNT4);
    } ans = (ans + cnt2-cnt3/3 + cnt4/6)% MoD;
    if (ans < 0) ans + + mod;
printf ("%lld\n", ans); }
4558: [JLoi2016] Side Description

God said, do not circle, want square, so then have this problem. Because we should side, and preferably be able to square, so God sent us to find the square
God sent us to a square with N rows M columns, a total of (n+1) x (m+1) lattice points, all we need to do is find out these lattice shapes.
How many squares (in other words, the four vertices of a square are lattice points). But this problem is too difficult for us because there are too many points.
, so God erased the K points in this (n+1) x (m+1). Since the point is less, the problem becomes simple, then these lattice points are composed
How many squares are there? Input

The first line of three integers N, M, K, represents the number of rows, columns, and vertices that cannot be selected for the chessboard. Guaranteed N, M >= 1, K <= (n + 1) x
(M + 1). The grid points for each row are numbered from top to bottom, followed by integers 0 through N, and the grid points of each column are numbered 0 through M. Next K line, every
Row two integer x,y the lattice point representing column x row y is deleted. Guaranteed 0 <=x <=n<=10^6, 0 <=y<=m<=10^6,k<=2*1000 and no
A duplicate lattice point appears. Output

A single positive integer that represents the value of a square number after modulo 100000007 (10^8 + 7) Sample Input

2 2 4
1 0 1 2 0 1 2 1
Sample Output
1

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.