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 <(const range &a) const
	{
	    return l<a.l;
	}
}line[505];
double dist(point a,point b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double r;
int n,t;
int main()
{
    while (scanf("%d",&n)!=EOF && n)
    {
	scanf("%lf%lf",&p.x,&p.y);
	for (int i=1;i<=n;i++)
	{
	    scanf("%lf%lf%lf",&q.x,&q.y,&r);
	    double d=dist(p,q);
	    double a=asin(r/d),b=asin((p.x-q.x)/d);
	    // printf("a:%lf b:%lf\n",a,b);
	    line[i].r=p.x-p.y*tan(b-a);
	    line[i].l=p.x-p.y*tan(a+b);
	    //   printf("%d : %lf~%lf\n",i,p.y*tan(b-a),p.y*tan(b+a));
	}
	sort(line+1,line+1+n);
	double L=line[1].l,R=line[1].r;
	for (int i=2;i<=n;i++)
	{
	    if (line[i].l>R)
	    {
		printf("%.2f %.2f\n",L,R);
		L=line[i].l,R=line[i].r;
	    }
	    else R=max(R,line[i].r);
	}
	printf("%.2f %.2f\n\n",L,R);
    }

    return 0;
}
时间: 2024-07-30 06:43:44

POJ 1375 Intervals | 解析几何的相关文章

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

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

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

解析几何,利用直角三角形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 1201 Intervals(图论-差分约束)

Intervals Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20779   Accepted: 7863 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end po

POJ 3670 Intervals(费用流)

POJ 3680 Intervals 题目链接 题意:给定一些区间,每个区间有一个权值,要求用这些区间去覆盖,每个点最多覆盖k次,问最多得到权值多少 思路:典型的区间k覆盖问题,区间连边容量1,代价-w,然后其他点相邻两两连边,容量k,代价0,跑一下费用流即可 代码: #include <cstdio> #include <cstring> #include <vector> #include <queue> #include <algorithm&g

POJ 3680 Intervals 离散 + 费用流

Intervals Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6246   Accepted: 2542 Description You are given N weighted open intervals. The ith interval covers (ai, bi) and weighs wi. Your task is to pick some of the intervals to maximize t

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 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 t

POJ 1201 Intervals(差分约束+spfa 求最长路径)

题目链接:http://poj.org/problem?id=1201 Description You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end points and integers c1, ..., cn from the standard input, com