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 ...
随机推荐
- 同一客户端多个git账号的配置
同一客户端多个git账号的配置 同一客户端多个git账号的配置 步骤一:用ssh-keygen命令生成一组新的id_rsa_new和id_rsa_new.pub. 1 ssh-keygen -t rs ...
- Pull Request的正确打开方式(如何在GitHub上贡献开源项目)
Pull Request的正确打开方式(如何在GitHub上贡献开源项目) GitHub的官方帮助如下: Fork A Repo: https://help.github.com/articles/f ...
- 【学习总结】GirlsInAI ML-diary day-20-初识 Kaggle
[学习总结]GirlsInAI ML-diary 总 原博github链接-day20 初识kaggle 1-注册一个账号(由于被谷歌收购,因此可能需要梯子) 2-Competition - 学会看一 ...
- supermap idesktop连接oraclesptial数据源
1.要使用相同的版本,如iServer 9D, iDesktop9D ,32位的 plsql,32位的 oracleinstance_client 11g 2.当时遇到的问题是使用oracleinst ...
- hibernate 插入Java.uitil.date时时分秒丢失问题解决
<property name="cj_time" column="cj_time"/> 不需要手动定义类型(定义了只能精确到日) new Date ...
- LOJ6435 PKUSC2018 星际穿越
这个题吧当时在考场只得了45分 然后70分的性质都分析到了 不知道为啥就是写萎蛋了 哎 当时还是too young too simple 看了一下julao们的博客这个题有两种做法 一个是比较费脑子的 ...
- 【leetcode】416. Partition Equal Subset Sum
题目如下: 解题思路:对于这种判断是否的题目,首先看看动态规划能不能解决.本题可以看成是从nums中任选i个元素,判断其和是否为sum(nums)/2,很显然从nums中任选i个元素的和的取值范围是[ ...
- Oracle11g新建用户及用户表空间
/* 建立数据表空间 */CREATE TABLESPACE SP_TAB DATAFILE '/u01/app/oracle/oradata/orcl/tab1_1.dbf' size 1024M ...
- Navicat Premium 12 如何连接阿里云虚拟主机SQL Server 数据库
这个是一台 阿里云购买云虚拟主机!密码已经重置完毕,现在我们 需要知道 数据连接的地址,数据库名,帐号以及密码. 根据不同的运营商 选择 这里我们选择阿里云 云数据库 SQL Server版本 填写 ...
- npm和gem
https://blog.csdn.net/u011099640/article/details/53083845