The so-called daily #4-the abolition of the Emperor Chan practices position thief mengde dedication Knife

Source: Internet
Author: User


Codeforces 459A Pashmak and garden

There is a square on the two-dimensional plane, and its edge is parallel to the axis. Now give two points and ask if there is a square vertex that is these two points. Outputs the coordinates of the other two points, if any.

It would be nice to have a discussion on the side-length relationship.

1#include <stdio.h>2#include <algorithm>3 4 intx[4],y[4];5 6 intMain () {7      for(inti =0; I <2; ++i) {8scanf"%d%d",&x[i],&y[i]);9     }Ten     intDX = x[0]-x[1]; One     intDY = y[0]-y[1]; A     if(dx!=0&& dy!=0&& std::abs (dx)! =std::abs (DY)) { -Puts"-1"); -         return 0; the     } -     if(dx==0) { -x[2] = x[0] +dy; -y[2] = y[0]; +x[3] = x[1] +dy; -y[3] = y[1]; +}Else if(dy==0) { Ax[2] = x[0]; aty[2] = y[0] +DX; -x[3] = x[1]; -y[3] = y[1] +DX; -}Else { -x[2] = x[0]; -y[2] = y[1]; inx[3] = x[1]; -y[3] = y[0]; to     } +printf"%d %d%d%d\n", x[2],y[2],x[3],y[3]); -     return 0; the}
View Code


Codeforces 566D Restructuring Company

There is a row of n (<= 2e5) points that perform 5e5 operations. There are three kinds of operation: (1,x,y) connect x point with Y Point, (2,x,y) connect (x,x+1,x+2...y-1,y), (3,x,y) ask whether X point and Y point are connected.

It looks very, very well, and it's got wood.

Requires two and check sets, 1 maintenance connectivity, and 1 references to daily #1div1, and maintains only the right connecting point for each point under Operation 2.

Finally someone in the game time over the Div.1 of the problem, moved AH have wood.

1#include <bits/stdc++.h>2 3 Const intN =200000+5;4 intn,m;5 intdsu[2][n];6 7 intFindint*DSU,intx) {8     returnDSU[X] = = x? X:DSU[X] =find (Dsu,dsu[x]);9 }Ten  One intMain () { Ascanf"%d%d",&n,&m); -      for(inti =0; I <= N; ++i) { -dsu[0][i] = dsu[1][i] =i; the     } -      while(m--) { -         intop,a,b; -scanf"%d%d%d", &op,&a,&b); A--; B--; +         if(OP = =1) { -             intx = Find (dsu[0],a); +             inty = Find (dsu[0],b); Adsu[0][X] =y; at}Else if(OP = =2) { -              for(inti = Find (dsu[1],A); I < b; dsu[1][i] = i +1, I = Find (dsu[1],i)) { -                 intx = Find (dsu[0],i); -                 inty = Find (dsu[0],i +1); -dsu[0][X] =y; -             } in}Else { -Puts (Find (dsu[0],a) = = = Find (dsu[0],B)?"YES":"NO"); to         } +     } -}
View Code

The so-called daily #4-the abolition of the Emperor Chan practices position thief mengde dedication Knife

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: 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.