首页 > 其他分享 >uva688 (扫描线)

uva688 (扫描线)

时间:2022-10-19 16:38:36浏览次数:63  
标签:yi qu int double uva688 扫描线 ans ri



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;
}



标签:yi,qu,int,double,uva688,扫描线,ans,ri
From: https://blog.51cto.com/u_15836782/5775940

相关文章

  • AcWing 算法提高课 线段树+扫描线法 求矩形之并的面积
    例题:求解多个长方形之并的面积https://www.acwing.com/problem/content/249/蓝色表示长方形,红色表示扫描线如下图所示,对于每一个横向的区间,在纵向维护线段树根据纵向......
  • 矩形面积并(扫描线)
      思路:扫描线的思路很容易确定,但难点在于如何实现。这里避免写持久化标记,最初的想法是记录区间内0的个数(即未覆盖点的个数),但是如此一来每一次更新都需要将tag下放到最......
  • 浅谈扫描线
    准备学习扫描线的时候,发现洛谷日报上并没有关于扫描线的文章,于是心血来潮想写一篇。顺便纪念一下我马上结束的OI生涯。前置知识线段树或树状数组(不会的请【模板】线......
  • 扫描线
    1离线2支持单点查询3单点维护操作顺序及其他信息从而维护历史信息(数据结构基于操作这一维)4对操作进行差分扫描时扫到改点时留存的操作就是位于该点的操作5可对数据结......
  • 扫描线
    扫描线的一些经典应用:求n个矩形的面积并和周长并。面积并(P5490【模板】扫描线)首先扫描线的思想就是假设有一条无限长度的线从一个方向到另一个方向扫一遍整个图形,这样......
  • 模拟赛 d (扫描线,三维偏序,线段树合并,并查集,线段树上二分)
    PRO题目大意:给定$N$个矩形,求连通块个数。($1\leqN,x_1,x_2,y-1,y_2\leq100000$)SOL乍一看就能知道是扫描线,不过这题的细节恐怖的要命。(std同样看不懂,自己魔改了一......
  • 【学习笔记/模板】扫描线 周长并
    先开坑,晚上再写。P1856[IOI1998][USACO5.5]矩形周长PictureCode#include<cstdio>#include<algorithm>usingnamespacestd;constintMAXN=1e5+10;intn,......
  • acwing 1228. 油漆面积 扫描线
     X星球的一批考古机器人正在一片废墟上考古。该区域的地面坚硬如石、平整如镜。管理人员为方便,建立了标准的直角坐标系。每个机器人都各有特长、身怀绝技。它们感兴......