A mobile phone company ACMICPC (Advanced Cellular, Mobile, and Internet-Connected Phone Corporation)is planning to set up a collection of antennas for mobile phones in a city called Maxnorm.The company ACMICPC has several collections for locations of antennas as their candidate plans, andnow they want to know which collection is the best choice.For this purpose, they want to develop a computer program to find the coverage of a collection ofantenna locations. Each antenna Ai has power ri, corresponding to “radius”. Usually, the coverageregion of the antenna may be modeled as a disk centered at the location of the antenna (xi, yi) withradius ri. However, in this city Maxnorm such a coverage region becomes the square [xi − ri, xi + ri] ×[yi − ri, yi + ri]. In other words, the distance between two points (xp, yp) and (xq, yq) is measured bythe max norm max{|xp −xq|, |yp −yq|}, or, the L∞ norm, in this city Maxnorm instead of the ordinaryEuclidean norm √(xp − xq)2 + (yp − yq)2.As an example, consider the following collection of 3 antennas4.0 4.0 3.05.0 6.0 3.05.5 4.5 1.0depicted in the figure on the right where the i-th row representsxi, yi, ri such that (xi, yi) is the position of the i-thantenna and riis its power. The area of regions of pointscovered by at least one antenna is 52.00 in this case.Write a program that finds the area of coverage by a givencollection of antenna locations.InputThe input contains multiple data sets, each representing a collection of antenna locations. A data setis given in the following format.nx1 y1 r1x2 y2 r2. . .xn yn rnThe first integer n is the number of antennas, such that 1 ≤ n ≤ 100. The coordinate of the i-thantenna is given by (xi, yi), and its power is ri. xi, yi and ri are fractional numbers between 0 and 200inclusive.The end of the input is indicated by a data set with ‘0’ as the value of n.OutputFor each data set, your program should output its sequence number (1 for the first data set, 2 for thesecond, etc.) and the area of the coverage region. The area should be printed with two digits to theright of the decimal point, after rounding it to two decimal places. The area may be 0.00.The sequence number and the area should be printed on the same line with no spaces at thebeginning and end of the line. The two numbers should be separated by a space.Sample Input34.0 4.0 3.05.0 6.0 3.05.5 4.5 1.023.0 3.0 3.01.5 1.5 1.00Sample Output1 52.002 36.00


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int mx = 110;
struct ax{
double a, b, h;
int f;
}e[mx * 2];

struct{
double l ,r ;
int cov, flag;
}t[mx * 8]; //8倍
int n;
double qu[2 * mx];
bool cmp(ax a, ax b){
return a.h < b.h;
}
void built(int i , int l , int r){
t[i].l = qu[l]; t[i].r = qu[r];
t[i].cov = t[i].flag = 0;
if(l+1 >= r){
t[i].flag = 1;
return ;
}
int mid = (l+r) / 2;
built(i*2, l, mid);
built(i*2+1, mid, r);
}
double update(int i, double l , double r, int f){
if(t[i].flag){
if(l <= t[i].l&&t[i].r <= r)
t[i].cov += f;
if(t[i].cov)
return t[i].r - t[i].l;
else
return 0;
}
return update(2 * i, l, r,f) + update(2 * i + 1, l, r,f);
}
int main(){
double x, y, r,sum,te;
int ans, d, ca = 0;
while(scanf("%d", &n) && n){
ans = 1;
d = 0;
te = n;
while(te--){
scanf("%lf%lf%lf", &x, &y, &r);
if(fabs(r-0)<=1e-6){
d++;
continue;
}

qu[ans-1] = e[ans].a = e[ans+1].a = x - r;
qu[ans] = e[ans].b = e[ans + 1].b = x + r;
e[ans].f = 1; e[ans+1].f = -1;
e[ans].h = y - r; e[ans+1].h = y + r;
ans+=2;
}
n -= d;
// cout<<d<<endl;
sort(qu, qu + 2 * n);
sort(e + 1, e + 1 +2 *n, cmp);
int k = 1;
for(int i = 1; i < 2*n; i++) //去重
if(qu[i] != qu[i - 1])
qu[k++] = qu[i];
// n = k;
built(1, 0, k-1);
sum = 0;
for(int i = 1; i < 2*n; i++)
sum+=(e[i+1].h - e[i].h) * update(1,e[i].a, e[i].b, e[i].f);
printf("%d %0.2lf\n", ++ca, sum);
}

return 0;
}