POJ 3347 Kadj Squares--extended length, geometry, segment coverage

Source: Internet
Author: User

Test instructions: N squares, side length is s[i], oblique 45 degrees in order to lay on the axis, as far as possible to the left, but not with any previous intersection, ask from the top down, which squares are visible.

Solution: We first expand the edge length to sqrt (2) times the edge length, so that you can directly perform integer operations.

And then in two steps:

1. Find out all the b[i]

2. Then the interval coverage decision

The first step: when we know all the previous b[j], B[i] is one of the leftmost positions that does not intersect with any of the preceding. To be satisfied with the front is not intersect and the most left, we have: b[i] = max (B[i],b[j]+2*min (S[I],S[J)), according to, push can be drawn.

The second step: the l,r of all squares have been calculated, and then n^2 to update the l,r of each square as visible l,r:

1. If s[i] > S[j] (j=1~i-1), and Seg[i]. L < Seg[j]. R, then seg[j]. R = Seg[i]. L

2. If s[i] < s[j]. , and Seg[i]. L < Seg[j]. R, then seg[i]. L = Seg[j]. R

--------------------------------------------------------------------------------------------------

Code:

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>using namespacestd;//Data Segmentints[ -],b[ -];structseg{intL,r,len;} seg[ -];//Data EndsintMain () {intn,i,j; DoubleGen2 = sqrt (2.0);  while(SCANF ("%d", &n)!=eof &&N) { for(i=1; i<=n;i++) scanf ("%d",&R[i]); b[1] = s[1];  for(i=2; i<=n;i++) {B[i]= b[i-1];  for(j=i-1; j>=1; j--) B[i]= Max (B[i],b[j] +2*min (s[i],s[j])); }         for(i=1; i<=n;i++) {Seg[i]. L= B[i]-S[i]; Seg[i]. R= B[i] +S[i]; Seg[i]. LEN=S[i]; }         for(i=1; i<=n;i++)        {             for(j=1; j<i;j++)            {                if(Seg[i]. LEN > Seg[j]. LEN && Seg[i]. L <Seg[j]. R) Seg[j]. R=Seg[i].                L if(Seg[i]. LEN < Seg[j]. LEN && Seg[i]. L <Seg[j]. R) Seg[i]. L=Seg[j].            R }        }        intFIR =1;  for(i=1; i<=n;i++)        {            if(Seg[i]. L <Seg[i]. R) {if(FIR) cout<<i, fir =0; Elsecout<<" "<<i; }} puts (""); }    return 0;}
View Code

POJ 3347 Kadj Squares--extended length, geometry, segment coverage

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.