POJ1375-Intervals

来源:互联网 发布:智能手环 数据接口 编辑:程序博客网 时间:2024/05/17 00:01
Intervals
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 3970 Accepted: 1149

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.

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

6300 45070 50 30120 20 20270 40 10250 85 20220 30 30380 100 1001300 300300 150 901300 300390 150 900

Sample Output

0.72 78.8688.50 133.94181.04 549.9375.00 525.00300.00 862.50

Source

Central Europe 1996
//AC代码
/*题意:有一个光源,下面有n个圆,求被遮住的阴影左右坐标此题求出圆心和光源与圆切线那个点的两个夹角,再利用正切tan就能求出(无关正负)*/#include<iostream>#include<queue>#include<cstdio>#include<algorithm>#include<cstring>#include<iomanip>#include<map>#include<cstdlib>#include<cmath>#include<vector>#define LL long long#define IT __int64#define zero(x) fabs(x)<eps#define mm(a,b) memset(a,b,sizeof(a))const int INF=0x7fffffff;const double inf=1e8;const double eps=1e-10;const double PI=acos(-1.0);const int Max=20001;using namespace std;int sign(double x){    return (x>eps)-(x<-eps);}typedef struct NODE{    double x;    double y;    double r;    void input()    {        scanf("%lf%lf%lf",&x,&y,&r);    }    void output()    {        cout<<x<<" "<<y<<" "<<r<<endl;    }}point;point start,node[Max];typedef struct LINE{    double st;    double ed;}Line;Line line[Max],interval[Max];double xmult(point p0,point p1,point p2){return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);}double dmult(point p0,point p1,point p2){return(p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y);}double Distance(point p1,point p2)// 返回两点之间欧氏距离{return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );}bool cmp(Line u,Line v){    return u.st<v.st;}int main(){    int n,m,i,j;    while(cin>>n&&n)    {        scanf("%lf%lf",&start.x,&start.y);        for(i=0;i<n;i++)        {            node[i].input();            double L,as1,as2,A,B;            L=Distance(start,node[i]);            as1=node[i].r/L;            A=asin(as1);            as2=(start.x-node[i].x)/L;            B=asin(as2);            line[i].st=start.x-start.y*tan(A+B);            line[i].ed=start.x-start.y*tan(B-A);        }        sort(line,line+n,cmp);        double L=line[0].st,R=line[0].ed;        m=0;        interval[m]=line[0];        //cout<<line[0].st<<" "<<line[0].ed<<endl;        for(i=1;i<n;i++)        {            if(interval[m].ed>=line[i].st)                interval[m].ed=max(line[i].ed,interval[m].ed);            else            {                interval[++m]=line[i];            }        }        for(i=0;i<=m;i++)        cout<<setprecision(2)<<setiosflags(ios::fixed)<<interval[i].st<<" "<<interval[i].ed<<endl;        cout<<endl;    }    return 0;}

0 0
原创粉丝点击