Poj1039 -- Pipe (Computational ry)

Source: Internet
Author: User

Poj1039 -- Pipe (Computational ry)

 

A pipe has n fold points. The coordinates (x1, y1) (x2, y2) of the n points on the wall of the pipe are given.

If you want to make the light the farthest, in addition to the possibility of the whole process, light will surely be at the intersection of a pipe wall and will be at the intersection of two nodes in the pipe. Otherwise, you can adjust the light angle, let the image go further, enumerate the positions of the two points, and then judge the intersection position one by one.

 

# Include
 
  
# Include
  
   
# Include
   
    
# Include using namespace std; # define eqs 1e-9/* intersection of two straight lines, seeking focus ax + by + c = 0; ux + vy + w = 0; a/u! = B/v prevents parallel intersections: (B * w-v * c)/(a * v-u * B), (c * u-a * w) /(a * v-u * B) */struct point {double x, y;} p [30]; int n; double a [4] [4] = {0, 0, 0}, {0,-, 0}, {0, 0,-1}, {0, -1 }}; double solve (point u, point v) {double a = (u. y-v.y)/(u. x-v.x), B = u. y-a * u. x; double x, y, ans = 0.0; int flag = 0, I; y = a * p [0]. x + B; if (y-p [0]. y> = eqs | p [0]. y-1.0-y> = eqs) return ans; for (I = 1; I <n; I ++) {y = A * p [I]. x + B; if (y-p [I]. y> eqs) {flag = 1; break;} else if (p [I]. y-1.0-y> eqs) {flag = 2; break;} else ans + = (p [I]. x-p [I-1]. x);} if (! Flag) return ans; u = p [I-1], v = p [I]; if (flag = 2) u. y-= 1.0, v. y-= 1.0; double k = (u. y-v.y)/(u. x-v.x), c = u. y-k * u. x; x = (B-c)/(k-a); ans + = (x-p [I-1]. x); return ans;} int main () {int I, j, k; double max1, temp; point u, v; while (scanf (% d, & n) & n) {max1 = 0.0; for (I = 0; I <n; I ++) scanf (% lf, & p [I]. x, & p [I]. y); for (I = 0; I <n; I ++) for (j = I + 1; j <n; j ++) for (k = 0; k <4; k ++) {u. x = p [I]. x + a [k] [0]; u. y = p [I]. y + a [k] [1]; v. x = p [j]. x + a [k] [2]; v. y = p [j]. y + a [k] [3]; temp = solve (u, v); if (temp> max1) max1 = temp ;}if (fabs (p [n-1]. x-p [0]. x-max1) <eqs) printf (Through all the pipe .); else printf (%. 2lf, p [0]. x + max1) ;}return 0 ;}
   
  
 


 

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.