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. 分析abex'crackme#2

    文件地址:https://www.wocloud.com.cn/webclient/share/sindex.action?id=i9K_Br6TgE4gbyGIlYkffWKcRy5TUdZ8U6_ ...

  2. call和apply,函数伴侣

    Predefined:js中的this指向直接运行上下文. call和apply是ECMASCRIPT 3在函数原型上所定义的方法,目的在于改变或指定this的指向,从而改变函数直接执行上下文.两者的 ...

  3. WEEX-EROS开发小笔记

    本文是作者之前刚接触移动端跨平台开发,使用weex-eros开发项目平日里记下来的一些笔记,分享出来方便为新手解惑,weex-eros是weex的一套解决方法,使用vue语法糖,对于前端开发者来说可以 ...

  4. activiti 5.22 表结构解析及清空流程运行测试数据

    1.结构设计 1.1.    逻辑结构设计 Activiti使用到的表都是ACT_开头的. ACT_RE_*: 'RE'表示repository(存储),RepositoryService接口所操作的 ...

  5. AbstractQueuedSynchronizer简单使用

    AQS是JUC中很多同步组件的构建基础,简单来讲,它内部实现主要是状态变量state和一个FIFO队列来完成,同步队列的头结点是当前获取到同步状态的结点,获取同步状态state失败的线程,会被构造成一 ...

  6. 特斯拉通过GitHub发布了这些源代码,用意何在?

    特斯拉多年来一直在软件社区使用开源软件而不遵守许可证. 在迈向合规性的一步中,特斯拉现在正在发布其软件的一些部分,这对特斯拉黑客和安全研究人员来说非常有用. 特斯拉是一家软件强大的公司,它一直在使用大 ...

  7. js百度地图API创建弧线并修改弧线的弧度

    去百度API官网下载CurveLine.min.js,注意复制下来的Js前面的行号要删除. // 百度地图API功能 var map = new BMap.Map("container&qu ...

  8. VueJS基础框架代码介绍

    参考文档 https://vuejs.bootcss.com/v2/api/ https://router.vuejs.org/zh-cn/essentials/getting-started.htm ...

  9. 获取mysql数据库表字段的备注信息

    SELECT COLUMN_NAME as field_name , COLUMN_COMMENT as remark  FROM information_schema.COLUMNS WHERE T ...

  10. LDD3 第9章 与硬件通信

    一.I/O端口和I/O内存 每种外设都通过读写寄存器进行控制.大部分外设都有几个寄存器,不管是在内村地址空间还是在I/O地址空间,这些寄存器的访问地址都是连续的. 在硬件层,内存区域和I/O区域没有区 ...