3835: Crop Circles
Description
Bessie and her fellow herd-mates have become extremely territorial. The N (1 <= N <= 400) cows conveniently numbered 1..N have all staked out a grazing spot in the pasture. Each cow i has a spot on an integer grid (0 <= X_i <= 10,000; 0 <= Y_i <= 10,000) and an integer radius R_i that indicates the circle she is staking out (1 <= R_i <= 500).The cows are a bit greedy and sometimes stake out territory of their herd-mates. For each cow, calculate the number of other cows whose territory overlaps her territory.By way of example, consider these six cows with indicated locations and radii (don't confuse radius with diameter!):
By visual inspection, we can see and count the overlaps, as shown.
NOTE: the test data will avoid pathological situations like tangents where the circles just barely touch.
Input
* Line 1: A single integer: N* Lines 2..N+1: Three space-separated integers: X_i, Y_i, and R_i
Output
* Lines 1..N: Line i contains a single integer that is the number of other fields that overlap with cow i's field.
Sample Input
6
7 7 716 14 711 13 210 17 329 8 515 7 4Sample Output
3
43202Source
Toj的一个题,问题只是n个圆和自己交的有多少个
#includeint x[410],y[410],r[410];int main(){ int n,i,j; scanf("%d",&n); for(i=0; i
矩形面积并,线段树经典
2719: 覆盖的面积
Description
给定平面上若干矩形,求出被这些矩形覆盖过至少两次的区域的面积.
Input
输入数据的第一行是一个正整数T(1<=T<=100),代表测试数据的数量.每个测试数据的第一行是一个正整数N(1<=N<=1000),代表矩形的数量,然后是N行数据,每一行包含四个浮点数,代表平面上的一个矩形的左上角坐标和右下角坐标,矩形的上下边和X轴平行,左右边和Y轴平行.坐标的范围从0到100000.注意:本题的输入数据较多,推荐使用scanf读入数据.
Output
对于每组测试数据,请计算出被这些矩形覆盖过至少两次的区域的面积.结果保留两位小数.
Sample Input
2
51 1 4 21 3 3 72 1.5 5 4.53.5 1.25 7.5 46 3 10 730 0 1 11 0 2 12 0 3 1Sample Output
7.63
0.00用先sort+二分离散化,再用线段树维护左右端点
#include#include using namespace std;const int N=2005;struct seg{ double l,r,h; int v; bool friend operator <(seg u,seg v) { return u.h 1)q[i].len=has[q[i].r+1]-has[q[i].l]; else if(q[i].l==q[i].r)q[i].len=0; else if(q[i].cnt==1)q[i].len=q[i*2].s+q[i*2+1].s; else q[i].len=q[i*2].len+q[i*2+1].len;}void update(int l,int r,int f,int i){ if(q[i].l==l&&q[i].r==r) { q[i].cnt+=f; pushup(i); return; } int mid=(q[i].l+q[i].r)/2; if(r<=mid)update(l,r,f,i*2); else if(l>mid)update(l,r,f,i*2+1); else { update(l,mid,f,i*2); update(mid+1,r,f,i*2+1); } pushup(i);}int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int k=0; for(int i=0; i