poj 1375 Intervals(计算圆的切线)

Intervals
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 3109   Accepted: 907

Description

In the ceiling in the basement of a newly open developers building a light source has been installed. Unfortunately, the material used to cover the floor is very sensitive to light. It turned out that its expected life time is decreasing dramatically. To avoid this, authorities have decided to protect light sensitive areas from strong light by covering them. The solution was not very easy because, as it is common, in the basement there are different pipelines under the ceiling and the authorities want to install the covers just on those parts of the floor that are not shielded from the light by pipes. To cope with the situation, the first decision was to simplify the real situation and, instead of solving the problem in 3D space, to construct a 2D model first. 
Within this model, the x-axis has been aligned with the level of the floor. The light is considered to be a point light source with integer co-ordinates [bx,by]. The pipes are represented by circles. The center of the circle i has the integer co-ordinates [cxi,cyi] and an integer radius ri. As pipes are made from solid material, circles cannot overlap. Pipes cannot reflect the light and the light cannot go through the pipes. You have to write a program which will determine the non-overlapping intervals on the x-axis where there is, due to the pipes, no light from the light source. 
poj 1375 Intervals(计算圆的切线)_第1张图片

Input

The input consists of blocks of lines, each of which except the last describes one situation in the basement. The first line of each block contains a positive integer number N < 500 expressing the number of pipes. The second line of the block contains two integers bx and by separated by one space. Each of the next N lines of the block contains integers cxi, cyi and ri, where cyi + ri < by. Integers in individual lines are separated by one space. The last block consists of one line containing n = 0.

Output

The output consists of blocks of lines, corresponding to the blocks in the input(except the last one). One empty line must be put after each block in the output. Each of the individual lines of the blocks in the output will contain two real numbers, the endpoints of the interval where there is no light from the given point light source. The reals are exact to two decimal places and separated by one space. The intervals are sorted according to increasing x-coordinate.

Sample Input

6
300 450
70 50 30
120 20 20
270 40 10
250 85 20
220 30 30
380 100 100
1
300 300
300 150 90
1
300 300
390 150 90
0

Sample Output

0.72 78.86
88.50 133.94
181.04 549.93

75.00 525.00

300.00 862.50

Source

Central Europe 1996

题目:http://poj.org/problem?id=1375

题意:给你一个灯和一些水管的切面,也就是圆,求这些圆在地面上形成的阴影

分析:由于题目的各种限制,所有就成了简单的计算切线问题,我这里是用极角来做的,首先求出圆心到点这条直线的极角,然后求出切点到圆心,和点到圆心的夹角,一减一加就得到两个极角,然后圆心向着两个极角移动r的距离,就是切点了,最后就是按比例求切线在x轴上的交点。。。

PS:发现极角好好用啊,就是不知道会不会出现精度问题,反正还没出现过^_^

还有这题我一厢情愿的认为n<100,re了啊= =

代码:

#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int mm=555;
struct seg
{
    double l,r;
}g[mm];
double cx,cy,r,bx,by,a1,a2;
int i,j,n;
bool cmp(seg a,seg b)
{
    return a.l<b.l;
}
double Dis(double sx,double sy,double tx,double ty)
{
    return sqrt((sx-tx)*(sx-tx)+(sy-ty)*(sy-ty));
}
double solve(double x,double y)
{
    return x+y*(x-bx)/(by-y);
}
int main()
{
    while(scanf("%d",&n),n)
    {
        scanf("%lf%lf",&bx,&by);
        for(i=0;i<n;++i)
        {
            scanf("%lf%lf%lf",&cx,&cy,&r);
            a1=atan2(by-cy,bx-cx);
            a2=acos(r/Dis(cx,cy,bx,by));
            g[i].l=solve(cx+r*cos(a1-a2),cy+r*sin(a1-a2));
            g[i].r=solve(cx+r*cos(a1+a2),cy+r*sin(a1+a2));
            if(g[i].l>g[i].r)swap(g[i].l,g[i].r);
        }
        sort(g,g+n,cmp);
        i=0;
        while(i<n)
        {
            cx=g[i].l;
            cy=g[i++].r;
            while(i<n&&g[i].l<=cy)cy=max(cy,g[i++].r);
            printf("%.2lf %.2lf\n",cx,cy);
        }
        puts("");
    }
    return 0;
}


你可能感兴趣的:(Integer,input,each,output,Numbers,Intervals)