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. ubuntu开发c/c++帮助文档

    1.C语言库函数基本的帮助文档 sudo apt-get install manpages sudo apt-get install manpages-de sudo apt-get install ...

  2. 07.Linux-CentOS系统库文件libaudit.so.1丢失问题

    问题:缺少共享库文件sudo: error while loading shared libraries: libaudit.so.1: cannot open shared object file: ...

  3. React(5) --绑定函数事件

    绑定函数事件 在以类继承的方式定义的组件中,为了能方便地调用当前组件的其他成员方法或属性(如:this.state),通常需要将事件处理函数运行时的 this 指向当前组件实例. run(){     ...

  4. linux ---JDK的安装与配置--两种方式

    linux下的JDK的安装与配置:JDK的安装有两种方式: tar包和rpm安装1.tar包安装: 下载地址:http://www.oracle.com/technetwork/java/javase ...

  5. Machine Learning:机器学习算法

    原文链接:https://riboseyim.github.io/2018/02/10/Machine-Learning-Algorithms/ 摘要 机器学习算法分类:监督学习.半监督学习.无监督学 ...

  6. spring cloud学习笔记五 网关服务zuul

    网关服务是指,客户端发送的请求不用直接访问特定的微服务接口,而且是经过网关服务的接口进行交互,网关服务再去到特定的微服务中进行调用.   网关服务的路由功能和Nginx的反向代理一样,所有的服务都先会 ...

  7. javascript 设置cookie和取得cookie

    代吗实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...

  8. JDBC和驱动类Driver

    什么是JDBC? JDBC(Java DataBase Connectivity),是一套面向对象的应用程序接口(API),制定了统一的访问各类关系数据库的标准接口,为各个数据库厂商提供了标准的实现. ...

  9. 如何将 不确定的有穷自动机(NFA) 转化为 确定的有穷自动机(DFA) 并将DFA最简化

    一.从NFA到DFA的转换 例如下图: DFA的每个状态都是一个由NFA中的状态构成的集合,即NFA状态集合的一个子集 r =aa*bb*cc* 二.从带有ε-边的NFA到DFA的转换 r=0*1*2 ...

  10. 05.配置为开发模式、配置静态资源locations、自定义消息转化器、FastJson

    配置为开发模式,代码做了修改,不用重新运行 idea需要该配置,mac测试无效 <dependency> <groupId>org.springframework</gr ...