UVA 688-mobile Phone Coverage

Source: Internet
Author: User

Classic problem, rectangular area and.      Solution: First, rectangular division, each rectangle two horizontal axis and two ordinate order, so that the 2n*2n interval, the interval to determine whether it is contained in the middle of n rectangles can be. Second, scan line. It hasn't been implemented yet. See: http://www.algorithmist.com/index.php/UVa_688 another: http://www.ii.uni.wroc.pl/boi/index.phtml?id=11

1#include <iostream>2#include <cstdio>3#include <algorithm>4 using namespacestd;5 6 intMain ()7 {8     intN, I, J, K, cases;9     DoubleArea, x[ the], y[ the], r[ the], dx[ the*2], dy[ the*2];TenCases =0; One      while(Cin>>n &&N) A     { -          for(i=0; i<n; i++) -         { theCIN >> X[i] >> Y[i] >>R[i]; -dx[i*2] = X[i]-r[i], dx[i*2+1] = X[i] +R[i]; -dy[i*2] = Y[i]-r[i], dy[i*2+1] = Y[i] +R[i]; -         } +Sort (DX, dx+2*n); -Sort (dy, dy+2*n); +Area =0.0; A          for(i =1; I <2*n; i++) at              for(j =1; J <2*n; J + +) -                  for(k =0; K < n; k++) -                 { -                     if(dx[i-1]>=x[k]-r[k] && dx[i]<=x[k]+R[k]) -                         if(dy[j-1]>=y[k]-r[k] && dy[j]<=y[k]+R[k]) -                         { inArea + = (Dx[i]-dx[i-1]) * (Dy[j]-dy[j-1]); -                              Break; to                         } +                 } -printf"%d%.2lf\n", ++cases, area); the     } *     return 0; $}

UVA 688-mobile Phone 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.