GDOI2017 simulation a try 4.11 Rotten girl's birthday

Source: Internet
Author: User
Description

Rotten girl to Birthday, Pty want to give a gift, but rotten girl in the classroom away from Pty classroom too far, so Pty will be moved and a star's Djy help send gifts. Djy in the school set up a plane Cartesian coordinate system, he stood at (0,0) point, the rotten girl at (x0,y0) point, djy each can only go up and down about four directions to move one step, in the middle of a rectangular teaching building, each teaching building gives two diagonal coordinates, and ensure that the surrounding area of each teaching building (as shown) there will be no other teaching building, that is, DJY can walk around a teaching building will not encounter any obstacles, now djy want to know from the starting point to the end of any teaching building, the shortest number of steps required. Input

The first line gives the x0,y0;
The second line gives N;
The following line x1,y1,x2,y2 each line, representing a pair of diagonal coordinates;
Ensure that each rectangle does not intersect, and that the surrounding area of a rectangle does not have a different rectangle. Output

Output is only one line: the shortest number of steps Sample Input

"Sample Input 1"
9 1
2
5-3 8 3
10-3 13 3
"Sample Input 2"
12 0
5
2-1 3 1
6-7 8-1
6 1 8 6
4 3 4 5
10-5 3 Sample Output

"Sample Output 1"
16
"Sample Output 2"
Data Constraint

Ensure that all y-coordinates are in [ -10^6,10^6]
All x-coordinates in [0,10^6]
70% Data Guarantee: n<=1000
100% Data Guarantee: n<=10^5 solution

This is amazing
all rectangles are on the right side of the Y axis, considering a left-to-right, scan line.
By test instructions obviously can only go from left to right, that is not to go to the left
then use a line tree to record each height up and down walk the minimum number of steps
walk around in the statistical answer add x0 can
then when the scan line to the right of a rectangle, The point on the rectangular edge can only move from the rectangular two corners to the middle, then you can determine how far to go, or find the demarcation point, the interval modification, only a single point of query Code

#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define FO (i,a,b)
for (int i=a;i<=b;i++) #define N 10010000 #define M 1000001 using namespace std;
int x0,y0,n,last[n],next[n],dat1[n],dat2[n],tot=0,mi=m,ma=-m,b[n],t[n],lz[n]; void Putin (int x,int y,int z) {next[++tot]=last[x];last[x]=tot;dat1[tot]=y;dat2[tot]=z;} void down (int v) {if (l
    z[v]==0) return;
    lz[v]=0;
    B[V*2]=B[V*2+1]=B[V];
    T[V*2]=T[V*2+1]=T[V];
Lz[v*2]=lz[v*2+1]=1;
    } int get (int v,int i,int j,int x) {if (i==j) return B[v]+abs ((x-m)-t[v]);
    int m= (I+J)/2;down (v);
    if (x<=m) return get (V*2,I,M,X);
else return get (v*2+1,m+1,j,x); } void Change (int v,int i,int j,int x,int y,int d1,int D2) {if (i==x&&j==y) {Lz[v]=1;b[v]=d1;t[v]
        =D2;
    Return
    } int m= (I+J)/2;down (v);
    if (y<=m) change (V*2,I,M,X,Y,D1,D2);
         else if (x>m) change (V*2+1,M+1,J,X,Y,D1,D2); else Change (V*2,I,M,X,M,D1,D2), ChanGE (V*2+1,M+1,J,M+1,Y,D1,D2);
    } int main () {freopen ("bl.in", "R", stdin);
    Freopen ("Bl.out", "w", stdout);
    scanf ("%d%d%d", &x0,&y0,&n);
        Fo (i,1,n) {int x1,y1,x2,y2;scanf ("%d%d%d%d", &x1,&y1,&x2,&y2);
    Vladimir Putin (X2+1,y1,y2); Mi=min (mi,y1); Ma=max (ma,y2);
    } mi--;ma++; Fo (i,0,x0) for (int j=last[i];j;j=next[j]) {int y1=dat1[j],y2=dat2[j],b1=get (1,mi+m,ma+m,y1-1+m), B2=get (1,mi+M
        , ma+m,y2+1+m), Y=B2+Y2+Y1-B1;
        if (Y1&LT;=Y/2) change (1,mi+m,ma+m,y1+m,y/2+m,b1+1,y1);
    if ((y+1)/2<=y2) Change (1,mi+m,ma+m, (y+1)/2+m,y2+m,b2+1,y2);
} printf ("%d\n", X0+get (1,mi+m,ma+m,y0+m)); }

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.