Selling Cells

Selling Cells

Description

Competition has been fierce among the cellphone providers in the town of Eastern WestField. Several companies have been running ads in which they each claim to provide more coverage to the town than do any of their competitors. 

AetherTech Telecommunications suspects that they, in fact, really do cover a larger portion of the town than do their competitors. They would like to compute their actual coverage so thay they can advertise the true amount.

The metropolitan area of EasternWestField will be modeled as a circle around the town center. The area covered by each cell tower can also be modeled as a circle, centered on the location of the tower, indicating the area within which a the tower provides sufficient signal strength for a phone to connect (e.g., one bar on the average phone�s signal strength meter).

All cell towers to be considered will have their centers within the metropolitan area, though their area of coverage may extend beyond the border of the metropolitan area. The areas covered by different towers can overlap, though for economic reasons no two towers have been constructed so close to one another that the center of one would lie within the coverage area of the other.

Compute the fraction of the metropolitan area within which a cell phone would be covered by at least one tower.

Input

Input consists of multiple data sets. Each data set begins with a line containing a single integer N, 1 ≤ N ≤ 25. This line is followed by N lines, each containing three floating point numbers x, y, r. These give the (x,y) coordinates of the circle�s center and the radius of that circle, respectively. The first circle in the list denotes the metropolitan area of Eastern Westfield. Each of the remaining N-1 circles describes a cell tower. 

The final data set is followed by a line containing a zero.

Output

For each data set, compute the fraction of the metropolitan area covered by the cell towers (as a number in the range 0.00...1.00 and print a line containing that fraction as a real number presented to 2 decimal points precision. 

Sample Input

2
10 10 10
10 10 5
2
0.404 0.0 1.0
-0.404 0.0 1.0
5
0 0 2
1 0 1
0 1 1
-1 0 1
0 -1 1
0

Sample Output

0.25
0.50
0.82

Note: The images corresponding to the sample input are:

这里写图片描述

题意:给出n个圆,问第一个圆被后面n-1个所覆盖的比例

解法:因为误差较少,直接枚举角度以及长度,加权搜索

#include <iostream>
using namespace std;
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int n;
double a[30][3], ans;

double sqr(double x) {
    return x*x;
}

int main() {
    cin >> n;
    while (n != 0) {
        for (int i = 1; i <= n; i++)
            cin >> a[i][1] >> a[i][2] >> a[i][0];
        double r, angel, x, y, ans = 0, sum = 0;
        int r1, angel1;
        bool flag;
        for (angel1 = 0; angel1 <= 628; angel1++)
        for (r1 = 0; r1 <= 1000; r1++) {
            //r1 = clock()*clock();
            //r1 = r1%int(a[1][0]*1000);
            r = r1;
            r = r*a[1][0]/1000;
            //r = r/1000;
            //angel1 = (clock()*clock())%314;
            angel = angel1;
            angel = angel/100;
            x = r*cos(angel)+a[1][1];
            y = r*sin(angel)+a[1][2];
            flag = false;
            for (int i = 2; i <= n; i++)
                if (sqrt(sqr(x-a[i][1])+sqr(y-a[i][2])) < a[i][0]) {
                    flag = true;
                    break;
                }
            if (flag) ans = ans+r1;
            sum = sum+r1;
        }
        ans = ans/sum;
        printf("%.2lf\n", ans);
        cin >> n;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值