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