UVA 11355 Cool Points( 极角计算 )
We have a circle of radius R and several line segments situated within the circumference of this circle. Let’s define a cool point to be a point on the circumference of this circle so that the line segment that is formed by this point and the centre of the circle makes no intersection with any of the given line segments.
For this problem, you have to find out the percentage of cool points from all possible points on the circumference of the given circle.
Input
The input file starts with an integer T(T<1000) that indicates the number of test cases. Each case starts with 2 integers N(0 <= N < 100) and R(0 < R < 1001). N represents the number of line segments and R represents the radius of the circle. Each of the next N lines contains 4 integers in the order x1, y1, x2 and y2. (x1, y1) – (x2, y2) represents a line segment.
You can assume that all the line segments will be inside the circle and no line segment passes through the origin. Also consider the center of the circle to be on the origin.
Output
For each input, output the case number followed by the percentage, rounded to 2 decimal places, of cool points. Look at the output for exact format.
Sample Input |
Output for Sample Input |
2 1 10 2 0 0 2 0 5 |
Case 1: 75.00% Case 2: 100.00% |
题意就是给出一个圆 , 还有一些线段( 不过圆心 )
问在圆上的点与圆心的连线没有交点的点占总点数的百分比。
那么就将所有线段的两个端点都弄成极角。然后排个序。
如果线段的两个端点极角分别跨越正负的话,就将它处理成两条线段 。
再处理一下区间 , 求百分比就能过了。
#include<bits/stdc++.h>
using namespace std;
const int N = ;
const double PI = acos(-1.0);
const double eps = 1e-;
typedef pair<double,double> pii;
#define X first
#define Y second
int n , top ;
vector<pii>p;
double x[N] , y[N]; int dcmp( double x ) {
if( fabs(x) < eps ) return ;
return x<?-:;
} double cal( double avg1 , double avg2 ) {
if( avg1 < && avg2 < ) return -1.0 ;
if( avg1 > && avg2 > ) return -1.0 ;
return fabs( avg1 ) + fabs( avg2 ) ;
}
void Solve() {
top = ;
for( int i = ; i < p.size() ; ++i ){
while( top > && dcmp( p[i].X-x[top-])== && dcmp(p[i].Y-y[top-])>= )top--;
if( top > && dcmp(x[top-]-p[i].X)<= && dcmp(y[top-]-p[i].Y)>= )continue ;
x[top] = p[i].X , y[top] = p[i].Y , top++;
}
}
void Run() {
double x1 , y1 , x2 , y2 , r ;
scanf("%d%lf",&n,&r); p.clear();
if( !n ) { puts("100.00%"); return ; }
for( int i = ; i < n ; ++i ){
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
double avg1 = atan2(y1,x1) , avg2 = atan2(y2,x2) ;
if( avg1 > avg2 ) swap( avg1 , avg2 );
double d = cal( avg1 , avg2 );
if( d == -1.0 ) { p.push_back(pii(avg1,avg2)); continue; }
if( d < PI ) {
p.push_back(pii(avg1,));
p.push_back(pii(,avg2));
}
else {
p.push_back(pii(-PI,avg1));
p.push_back(pii(avg2,PI));
}
}
sort( p.begin() , p.end() );
Solve();
double s = x[] , e = y[] , fenzi = ;
for( int i = ; i < top ; ++i ){
if( x[i] > e ) {
fenzi += ( e - s ); s = x[i];
}
e = y[i] ;
}
fenzi += ( e - s );
double ans = 100.0 - fenzi/(2.0*PI)*100.0;
printf("%.2lf",ans);puts("%");
} int main() {
// freopen("in.txt","r",stdin);
int _ , cas = ;
scanf("%d",&_); while( _ -- ) {
printf("Case %d: ",cas++);
Run();
}
}
UVA 11355 Cool Points( 极角计算 )的更多相关文章
- UVA 11355 Cool Points(几何)
Cool Points We have a circle of radius R and several line segments situated within the circumference ...
- UVA 10869 - Brownie Points II(树阵)
UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...
- uva 11355(极角计算)
传送门:Cool Points 题意:给一个圆心为原点的圆和一些线段,问所有线段两端点与圆心连线构成的角度总和占总360度的百分比. 分析:首先将所有线段的两端点变成极角,然后排序(范围[-PI,PI ...
- UVa 10295 - Hay Points
题目:有非常多工人.相应一个能力描写叙述表,每种能力有一个权值,求每一个工人的能力值. 分析:字符串.hash表,字典树.利用散列表或者字典树存储相应的单词和权值.查询就可以. 说明:注意初始化,计算 ...
- UVa 12714 Two Points Revisited (水题,计算几何)
题意:给定一条线段,让你求一条线段与已知线段垂直,并且所有线段的坐标的点的坐标都不大于给定的坐标的最大值且不能为负数. 析:没啥好说的,随便找一条就好. 代码如下: #pragma comment(l ...
- Matrix Matcher UVA - 11019AC_自动机 + 代价提前计算
Code: #include<cstdio> #include<cstring> #include<algorithm> #include<vector> ...
- 计算几何基础算法几何C++实现
This file is implementation of Common Common Computational Geometry Algorithms.Please please pay att ...
- 最短路径—Dijkstra算法和Floyd算法
原文链接:http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html 最后边附有我根据文中Dijkstra算法的描述使用jav ...
- ADC测试matlab代码
前面有做过ADC性能测试,测试方式是先使用ADC采集一个单频信号,然后利用matlab进行性能分析. 下面把matlab分析的代码记录下来: %The following program code p ...
随机推荐
- SR-IOV
SR-IOV 来源 http://blog.csdn.net/liushen0916/article/details/52423507 摘要: 介绍SR-IOV 的概念.使用场景.VMware 和 K ...
- crack Tut.ReverseMe1.exe
测试文件:https://www.wocloud.com.cn/webclient/share/sindex.action?id=i9K_Br6TgE7ZLB3oBGUcJmKcRy5TUdZ8U6_ ...
- Backend事后诸葛亮
事后诸葛亮 设想和目标 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们的软件想解决初学编程语言的入门困难.定义的不算太清楚,没有仔细地调查用户入门的困难之处. ...
- Python Web开发:Django+BootStrap实现简单的博客项目
创建blog的项目结构 关于如何创建一个Django项目,请查看[Python Web开发:使用Django框架创建HolleWorld项目] 创建blog的数据模型 创建一个文章类 所有开发都是数据 ...
- 04.Linux-CentOS系统SSH连接问题
问题:SSH远程连接时报错 Socket error Event: 32 Error: 10053.Connection closing...Socket close.Connection close ...
- NVIDIA Jetson™ TX1
NVIDIA® Jetson TX1 是一台模块式计算机,代表了视觉计算领域近20年的研发成就,其尺寸仅有信用卡大小.Jetson TX1 基于崭新 NVIDIA Maxwell™ 架构,配有256个 ...
- sqlserver 之 将查询结果变为json字符串
GO /****** Object: StoredProcedure [dbo].[SerializeJSON] Script Date: 6/4/2019 3:58:23 PM 将查询结果变为jso ...
- vagrant up ----失败 问题解决
命令行启动提示信息 there was an error while executing `vboxmanage`, a cli used by vagrant for controlling vir ...
- Activity(工作流-1)
1.activity自带数据表的含义(23张表) (1)资源库流程规则表 1)act_re_deployment 部署信息表 2)act_re_model 流程设计模型部署表 3)act_re_pr ...
- VMware安装MAC OS
测试环境 安装环境:win10 .VMware Workstation Pro14 镜像:OS X 10.11.5(由于太大,就没有上传网盘,网上也有很多资源) 安装准备 安装前先把关于VMware的 ...