POJ 3347 Kadj Squares (segment overlay)

Source: Internet
Author: User

Title: give you a few square side length, square a vertex on the x-axis and then the angle of the x-axis is 45 degrees, each square is close, ask from above to see the number of squares can see

Topic ideas: Line coverage, edge length multiply on 2 to prevent the generation of decimals, to find out each square and x-axis parallel diagonal of the starting x-coordinate, the rest is the line.

#include <cstdio>#include<cstdlib>#include<cmath>#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<queue>#defineINF 0x3f3f3f3f#defineMAX 100005using namespacestd;structnode{intSx,y,ex,dist;} Point[max];intVis[max],n;voidFind (intSxintExintPOS) {     for(intI=0; i<n; i++)    {        if(I==pos | | (Point[pos].y >=point[i].y)) Continue; if((sx>=point[i].sx && ex<=point[i].ex) | | sx>=ex) {Vis[pos]=1; return; }        Else if(Sx<=point[i].ex && sx>=point[i].sx) {SX=Point[i].ex; }        Else if(Ex<=point[i].ex && ex>=point[i].sx) {Ex=point[i].sx; }    }}intMain () {intD,sx,ex; intop;  while(SCANF ("%d",&N), N) {op=0; memset (Vis,0,sizeof(VIS));  for(intI=0; i<n; i++) {scanf ("%d",&d); Point[i].dist=D; Point[i].y=D; POINT[I].SX=0;  for(intj=0; j<i; J + +) {point[i].sx=max (Point[i].sx,point[j].ex-abs (point[i].dist-point[j].dist)); } Point[i].ex=point[i].sx+2*D; }         for(intI=0; i<n; i++) {ex=Point[i].ex; SX=point[i].sx;        Find (Sx,ex,i); }         for(intI=0; i<n; i++)        {            if(!Vis[i]) {                if(!op) {op=1; printf ("%d", i+1); }                Elseprintf ("%d", i+1); }} printf ("\ n"); }    return 0;}
View Code

POJ 3347 Kadj Squares (segment overlay)

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.