poj 1375(解析几何)

Intervals

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 4292   Accepted: 1288

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

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

大概看这个图就能够解除来了。。

这个题距离不能够取绝对值,因为下面这种情况最左边和最右边都要靠p0.x+一个正数

接下来排个序再合并区间就OK,

#include <iostream>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
using namespace std;
const int N = 505;
struct Point {
    double x,y,r;
}p[N],p0;
struct Line{
    double l,r;
}line[N];
double dis(Point a,Point b){
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cmp(Line a,Line b){
    if(a.l<b.l) return 1;
    return 0;
}
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF,n){
        scanf("%lf%lf",&p0.x,&p0.y);
        double angle1,angle2;
        for(int i=0;i<n;i++){
            scanf("%lf%lf%lf",&p[i].x,&p[i].y,&p[i].r);
            double l = dis(p[i],p0); ///p0到圆心的距离
            angle1 = asin(p[i].r/l);
            double len = (p0.x-p[i].x);///这里千万不能够取绝对值..因为后面的有可能是加
            angle2 = asin(len/l);
            line[i].l = p0.x - p0.y*tan(angle1+angle2);
            line[i].r = p0.x - p0.y*tan(angle2-angle1);
        }
        sort(line,line+n,cmp);
        /*for(int i=0;i<n;i++){
            printf("%lf %lf\n",line[i].l,line[i].r);
        }*/
        double l = line[0].l,r = line[0].r;
        for(int i=1;i<n;i++){
            if(line[i].l>r){
                printf("%.2lf %.2lf\n",l,r);
                l = line[i].l;
                r = line[i].r;
            }
            else{
                r = max(line[i].r,r);
            }
        }
        printf("%.2lf %.2lf\n\n",l,r);
    }
    return 0;
}
				
时间: 2024-10-24 02:54:46

poj 1375(解析几何)的相关文章

POJ 1375

可以通过顶角角度来计算切线与坐标轴的坐标 开始还以为有公式可以算,谁知道原来是解二元一次方程,靠.. #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MAX=1050; struct point{ double x; int flag; point(){ flag=0;} }p[MAX]; do

poj 1375 Intervals(解析几何 过圆外一点求与圆的切线)

题目大意:给出一个光源,给出一些圆,求投影区间. 如图,先可以求出角a,通过半径与PQ距离,而角b也可以求出.那么就可以求出两条切线与Y轴的夹角,分别为a+b,b-a. 之后利用角度求出各投影线段的左右顶点,排序判断即可. #include<iostream> #include<algorithm> #include<cmath> #include<cstdio> using namespace std; struct Point { double x,y;

POJ 1375 Intervals 解析几何 求圆的切线

题目大意:给出一个点,再给出都处于这个点之下的一些圆,求这个点光源照到这些圆上之后所得到的阴影的并集. 思路:求出每一个圆关于那个点的切线,每一个圆可以处理出来两个切线,这两个切线在x轴上交点的中间部分就是要求的阴影.最后将所有的阴影部分取并输出. 关于求切线,我是利用方向向量解方程做的.应该有更简洁的方法吧.. CODE: #include <cmath> #include <cstdio> #include <cstring> #include <iostre

POJ 1375 Intervals | 解析几何

参考了这个博客 #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> using namespace std; struct point { double x,y; point(){}; point(double _x,double _y) { x=_x,y=_y; } }p,q; struct range { double l,r; bool operator <

POJ 1375 Intervals

解析几何,利用直角三角形asin函数求出角来,然后根据y就可以算出x了 最后把点排序一下,入点+1,出点-1,由0变为1则是入点,由1变为0时则是出点 #include<stdio.h> #include<math.h> #include<algorithm> #include<string.h> using namespace std; struct Circle{ double x,y,r; }; struct Node{ double x; int f

[poj] 1375 Interval || 圆的切线&amp;和直线的交点

原题 每组数据给出一些圆(障碍物)的圆心和半径,一个点和一条线段,求站在这个点,能开到的线段的部分的左端点和右端点.没有则输出"No View" 相当于求过该点的圆的两条切线,切线外即为可见的地方. 借鉴于这个blog:http://blog.csdn.net/acm_cxlove/article/details/7896110 只要求出两条直线和竖直的夹角,然后通过向量旋转即可得到交点横坐标. #include<cstdio> #include<algorithm&

[转] POJ几何分类

转自:http://blog.csdn.net/tyger/article/details/4480029 计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行代码,里面大部分是模板.如果代码一片混乱,那么会严重影响做题正确率.4.注意精度控制.5.能用整数的地方尽量用整数,要想到扩大数据的方法(扩大一倍,或扩大sqrt2).因为整数不用考虑浮点误差,而且运算比浮点快. 一.点

【转】计算几何题目推荐

打算转下来好好做计算几何了. 原文地址:http://blog.sina.com.cn/s/blog_49c5866c0100f3om.html 其实也谈不上推荐,只是自己做过的题目而已,甚至有的题目尚未AC,让在挣扎中.之所以推荐计算几何题,是因为,本人感觉ACM各种算法中计算几何算是比较实际的算法,在很多领域有着重要的用途计算几何题的特点与做题要领:1.大部分不会很难,少部分题目思路很巧妙2.做计算几何题目,模板很重要,模板必须高度可靠.3.要注意代码的组织,因为计算几何的题目很容易上两百行

优质题表(机密版)

转载请注明出处:http://www.cnblogs.com/dashuzhilin/p/4556803.html 思维题: poj 1528 poj 1597 poj 2538 poj 2608 poj 2612 poj 2361 poj 2339 poj 2664 uva 10894 uva 10921   uva 10922   uva 10929 uva 10931   uva 10800   uva 10878 uva 10976   uva 10323   uva 201 poj 2