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%

view code#include <bits/stdc++.h>

using namespace std;
double PI = acos(-1.0);
int _, cas=1, n, r; struct event
{
double x;
int y;
bool operator < (const event &o) const{
return x<o.x;
}
event() {}
event(double x, int y):x(x),y(y) {}
}e[4321];
int ecnt; void addseg(double a, double b)
{
if(a>b) swap(a,b);
e[ecnt++] = event(a, 1);
e[ecnt++] = event(b, -1);
} int main()
{
// freopen("in.txt", "r", stdin);
cin>>_;
while(_--)
{
scanf("%d%d", &n, &r);
ecnt = 0;
double a,b,c,d;
for(int i=0; i<n; i++)
{
scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
double x = atan2(b,a), y = atan2(d,c);
if(x<y) swap(x, y);
if(x-y>PI)
{
addseg(-PI, y);
addseg(x, PI);
}
else addseg(x, y);
}
int eventnum = 0;
sort(e, e+ecnt);
double last = -PI, ans = 0.0;
for(int i=0; i<ecnt; i++)
{
if(eventnum==0)//这里很经典,记下
{
ans += e[i].x - last;
}
eventnum += e[i].y;
last = e[i].x;
}
ans += PI - last;
printf("Case %d: %.2f%%\n", cas++, (ans/(PI*2)*100));
}
return 0;
}

UVA 11355 Cool Points(几何)的更多相关文章

  1. UVA 11355 Cool Points( 极角计算 )

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

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

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

  3. uva 11355(极角计算)

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

  4. UVA 11796 Dog Distance(几何)

    Dog Distance [题目链接]Dog Distance [题目类型]几何 &题解: 蓝书的题,刘汝佳的代码,学习一下 &代码: // UVa11796 Dog Distance ...

  5. UVa 11971 - Polygon(几何概型 + 问题转换)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  6. UVa 11346 - Probability(几何概型)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  7. UVA 270 Lining Up (几何 判断共线点)

     Lining Up  ``How am I ever going to solve this problem?" said the pilot. Indeed, the pilot was ...

  8. uva 11178二维几何(点与直线、点积叉积)

    Problem D Morley’s Theorem Input: Standard Input Output: Standard Output Morley’s theorem states tha ...

  9. uva 11665 Chinese Ink (几何+并查集)

    UVA 11665 随便给12的找了一道我没做过的几何基础题.这题挺简单的,不过uva上通过率挺低,通过人数也不多. 题意是要求给出的若干多边形组成多少个联通块.做的时候要注意这题是不能用double ...

随机推荐

  1. ANT自动打包U3D安卓项目研究笔记

    概述 因项目使用Atlassian Stash作为项目源码管理端,且其支持Ant命令自动编译,可使其根据最新的代码自动打包,故产生该研究Ant打包的任务.在此将研究过程及一些相关知识整理记录在此. 本 ...

  2. [转]在SqlServer 中解析JSON数据

      在Sqlserver中可以直接处理Xml格式的数据,但因为项目需要所以要保存JSON格式的数据到Sqlserver中在博客:Consuming JSON Strings in SQL Server ...

  3. ViewPager和Fragment的组合使用

    如图是效果图用的是Viewpager和fragment来实现的主界面 不过其中的预加载我没有解决 如下是代码代码比较简单 package com.ithello.dingding; import ja ...

  4. javascript 之注意url特殊字符限制

    引子 浏览器URl地址,上网一定会用到,但是浏览器地址有中文或者浏览器url参数操作的时候,经常会用到encodeURIComponent()和decodeURIComponent()以及encode ...

  5. 【JVM】2、关于jdk7的MethodHandle类

    关于MethodHandle类,这个类是在jdk1.7之后加入的,这个类的作用类似函数指针的意思 这个类中有一个方法 这里我的jdk有一个问题,就是我在进行MethodHandle操作的时候,我们会发 ...

  6. Linux 安装 Nginx

    1. nginx的安装: 开始学习如何安装nginx,首先安装必要的软件: # yum install libtool # yum install -y gcc-c++ # yum install z ...

  7. Mac OSX 下用 Homebrew 安装 MongoDB 并配置到 WebStorm 中

    1. 安装 Ruby OSX 操作系统内置 Ruby,但如果没有 Ruby,则需先输入以下命令安装能够进行多版本ruby环境安装.管理和切换的命令行工具 RVM. 1.1 安装 RVM 打开终端输入以 ...

  8. 【JavaEE】Hibernate继承映射,不用多态查询只查父表的方法

    几个月前,我在博问里面发了一个问题:http://q.cnblogs.com/q/64900/,但是一直没有找到好的答案,关闭问题以后才自己解决了,在这里分享一下. 首先我重复一下场景,博问里面举的动 ...

  9. 再谈visibility:hidden和display:none

    之前写过一篇有关visibility:hidden和display:none的文章:为什么要用用visibility:hidden;代替display:none;?主要是从浏览器性能方面入手,却没写两 ...

  10. SAP debug的几种方式

         1. 直接在程序中设断点 这种方式想必大家都知道了,在se38里面打上breakpoint,程序运行到该处即进入debug模式   2.background Job的debug 进入SM37 ...