代码
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
#define Clear(a) memset(a,0,sizeof(a))
const long long mod = 1e9+7;
using namespace std;
const long long N = 8e5+100;
double x1[N], x2[N], z1[N], z2[N], kz[N], kx[N], ans;
long long n;
struct ss{ double z1, z2, v;long long x;}line[N];
bool cmp_by_x(ss a, ss b){
return a.x < b.x;
}
struct{
double l[N], r[N], v[N], s[N], ss[N];
void up(long long p){
if(v[p])
s[p] = ss[p];
else if(l[p] == r[p])
s[p] = 0;
else
s[p] = s[p << 1] + s[p << 1 | 1];
}
void bu(long long p, long long ll, long long rr){
l[p] = ll, r[p] = rr;
if(ll == rr){
ss[p] = kz[ll] - kz[ll - 1];
return ;
}
long long m = (ll + rr) >> 1;
bu(p << 1, ll, m);
bu(p << 1 | 1, m + 1, rr);
ss[p] = ss[p << 1] + ss[p << 1 | 1];
}
void add(long long p, long long ll, long long rr, double x){
if(ll <= l[p] && r[p] <= rr){
v[p] += x;
up(p);
return ;
}
long long m = r[p << 1];
if(ll <= m)
add(p << 1, ll, rr, x);
if(rr >= m + 1)
add(p << 1 | 1, ll, rr, x);
up(p);
}
}tr;
int main()
{
int q=1;
while(scanf("%lld", &n)!=EOF&&n!=0)
{
ans = 0;
for(long long i = 1; i <= n; i ++){
scanf("%lf %lf %lf %lf", &x1[i], &z1[i], &x2[i], &z2[i]);
// if(x1[i]>x2[i])swap(x1[i],x2[i]);
// if(z1[i]>z2[i])swap(z1[i],z2[i]);
}
for(long long i = 1; i <= n; i ++)
kx[i] = x1[i], kx[i + n] = x2[i],
kz[i] = z1[i], kz[i + n] = z2[i];
sort(kx + 1, kx + n * 2 + 1);
sort(kz + 1, kz + n * 2 + 1);
for(long long i = 1; i <= n; i ++){
x1[i] = lower_bound(kx + 1, kx + n * 2 + 1, x1[i]) - kx;
x2[i] = lower_bound(kx + 1, kx + n * 2 + 1, x2[i]) - kx;
z1[i] = lower_bound(kz + 1, kz + n * 2 + 1, z1[i]) - kz;
z2[i] = lower_bound(kz + 1, kz + n * 2 + 1, z2[i]) - kz;
}
for(long long i = 1; i <= n; i ++){
line[i].z1 = line[i + n].z1 = z1[i];
line[i].z2 = line[i + n].z2 = z2[i];
line[i].x = x1[i], line[i + n].x = x2[i];
line[i].v = 1, line[i + n].v = -1;
}
sort(line + 1, line + n * 2 + 1, cmp_by_x);
tr.bu(1, 1, n * 2);
for(long long i = 1; i <= n * 2; i ++){
ans += ((kx[line[i].x] - kx[line[i - 1].x]) * tr.s[1]) ;
tr.add(1, line[i].z1 + 1, line[i].z2, line[i].v);
}
printf("Test case #%d\n", q);
q++;
printf("Total explored area: %.2lf\n\n", ans);
}
return 0;
}