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 x1y1x2 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( 极角计算 )的更多相关文章

  1. UVA 11355 Cool Points(几何)

    Cool Points We have a circle of radius R and several line segments situated within the circumference ...

  2. UVA 10869 - Brownie Points II(树阵)

    UVA 10869 - Brownie Points II 题目链接 题意:平面上n个点,两个人,第一个人先选一条经过点的垂直x轴的线.然后还有一个人在这条线上穿过的点选一点作垂直该直线的线,然后划分 ...

  3. uva 11355(极角计算)

    传送门:Cool Points 题意:给一个圆心为原点的圆和一些线段,问所有线段两端点与圆心连线构成的角度总和占总360度的百分比. 分析:首先将所有线段的两端点变成极角,然后排序(范围[-PI,PI ...

  4. UVa 10295 - Hay Points

    题目:有非常多工人.相应一个能力描写叙述表,每种能力有一个权值,求每一个工人的能力值. 分析:字符串.hash表,字典树.利用散列表或者字典树存储相应的单词和权值.查询就可以. 说明:注意初始化,计算 ...

  5. UVa 12714 Two Points Revisited (水题,计算几何)

    题意:给定一条线段,让你求一条线段与已知线段垂直,并且所有线段的坐标的点的坐标都不大于给定的坐标的最大值且不能为负数. 析:没啥好说的,随便找一条就好. 代码如下: #pragma comment(l ...

  6. Matrix Matcher UVA - 11019AC_自动机 + 代价提前计算

    Code: #include<cstdio> #include<cstring> #include<algorithm> #include<vector> ...

  7. 计算几何基础算法几何C++实现

    This file is implementation of Common Common Computational Geometry Algorithms.Please please pay att ...

  8. 最短路径—Dijkstra算法和Floyd算法

    原文链接:http://www.cnblogs.com/biyeymyhjob/archive/2012/07/31/2615833.html 最后边附有我根据文中Dijkstra算法的描述使用jav ...

  9. ADC测试matlab代码

    前面有做过ADC性能测试,测试方式是先使用ADC采集一个单频信号,然后利用matlab进行性能分析. 下面把matlab分析的代码记录下来: %The following program code p ...

随机推荐

  1. DTS

    一.DTS的加载过程   如果要使用Device Tree,首先用户要了解自己的硬件配置和系统运行参数,并把这些信息组织成Device Tree source file.通过DTC(Device Tr ...

  2. 08.Linux系统启动root密码忘记及文件系统故障问题

    问题:root用户密码忘记了,在重置root密码时,出现文件系统故障,没有root密码进不去,怎么办? Error:UNEXPECTED INCONSISTENCY;RUN fsck MANUALIY ...

  3. python浮点数与整数间的转化

    舍弃小数部分 >>> math.trunc(12.533222) 12 >>> round(12.2544) 12 按给定小数位数四舍五入 >>> ...

  4. POJ 3237 树链剖分

    题目链接:http://poj.org/problem?id=3237 题意:给定一棵n个结点n-1条边的树. 每条边都是一个边权. 现在有4种操作 1:CHANGE I V:把(输入的)第i条边的边 ...

  5. Sass Maps的函数-map-values($map)、map-merge($map1,$map2)

    map-values($map) map-values($map) 函数类似于 map-keys($map) 功能,不同的是 map-values($map )获取的是 $map 的所有 value ...

  6. AcWing 244. 谜一样的牛 (树状数组+二分)打卡

    题目:https://www.acwing.com/problem/content/245/ 题意:有n只牛,现在他们按一种顺序排好,现在知道每只牛前面有几只牛比自己低,牛的身高是1-n,现在求每只牛 ...

  7. 神秘的java Https

    说起网络安全,最基本的策略就是走https.https仿佛一条神秘通道,有了它,万事无忧. 究竟什么是https?如何实现https? 本文将揭开https的神秘面纱. WTF https 万事皆有源 ...

  8. net core配置log4net需要注意的地方

    和netframework不一样的是,netcore 没有assembly文件.所以配置的时候需要注意: 1.配置文件可以没有 <configSections> <section n ...

  9. Red Hat 6网络配置笔记

    1.重启网卡/etc/init.d/network restart server network restart2.运行结果报错 关闭NetworkManagerservice NetworkMana ...

  10. 抓包工具fiddler下载配置(三):手机设置代理

      前言 本篇仅讲解了手机端如何设置代理,是[抓包工具fiddler下载配置(一):下载/安装&信任证书]的后续文章,未下载安装抓包工具的需先参考文章[抓包工具fiddler下载配置(一):下 ...