A simple probability problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Total Submission(s): 43    Accepted Submission(s): 14

Problem Description
Equally-spaced parallel lines lie on an infinite plane. The separation between adjacent lines is D (D>0). Now considering a circle of diameter D. N points lie on or in the circle. It is guaranteed that
any three points are not collinear. Between any two points there's a needle. Find the possibility that, if the circle is randomly (with equal probability on any position and direction) thrown onto the same plane described above (with the equally-spaced parallel
lines of separation d), at least one needle crosses a line.
 
Input
The first line contains a single integer T (1 <= T <= 100), the number of test cases.



For each set of input data, the first line gives two integers, N and D (N<=100), as described above.
You can consider the center of the circle is default as the origin. Lastly N lines is followed, each containing two real numbers that representing the coordinate of a point lying within the circle.
 
Output
Each output should occupy one line. Each line should start with "Case #i: ", followed by a real number round to four decimal places, the probability that at least one needle crosses one line.
 
Sample Input
2
2 2
-0.5 0
0.5 0
3 3
0 1
1 0
-1 0
 
Sample Output
Case #1: 0.3183
Case #2: 0.5123
 
Source
2014 Multi-University Training Contest 10





题目链接  :http://acm.hdu.edu.cn/showproblem.php?pid=4978





题目大意  :一个无限大的平面上有无数条等距平行线,每两条间距为D,给一个直径为D的圆,有n个点分布在圆上或者圆内,点的输入是依照已圆心为原点的坐标系,规定随意三点不共线。随意两点间的线段记为一根针。如今问将该圆投到平面上至少有一根针和当中一条平行线相交的概率





题目分析  :计算几何的问题,首先考虑仅仅有两点的情况即一根针。这就是一个布丰投针问题,公式为P=2L/πD (L为针长。D为平行线间距)。再考虑多个点,显然是个凸包问题,假设凸包边上的线能够与平行线相交,凸包内的线必定能够与平行线相交,由投针问题的推广我们能够得到公式P = C/πD (C为凸包周长),详见

url=s3rJRGUhCZ7kmsXA6o7Edr8h1rJJbibu2Ocs1Yf5BpsPwSkjkK9w-uVSV4d-cBGV36UA9bpxVfqLLA9qlPwbWkYbjkFzDaP_N5dtWHVT_mi">布丰投针及推广




#include <cstdio>
#include <cstdlib>
#include <cmath>
#define N 200
#define inf 1e-6
#define PI 3.141592653
typedef struct
{
double x;
double y;
}point;
point points[N];
point chs[N];
int sp; //求凸包周长的模板
double dis(point a, point b)
{
return sqrt((a.x - b.x) * (a.x - b.x) * 1.0 + (a.y - b.y) * (a.y - b.y));
} double multi(point p0, point p1, point p2)
{
return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);
}
int cmp(const void *p, const void *q)
{
point a = *(point *)p;
point b = *(point *)q;
double k = multi(points[0], a, b);
if(k < -inf)
return 1;
else if(fabs(k) < inf && (dis(a, points[0]) - dis(b, points[0])) > inf)
return 1;
else return -1;
}
void convex_hull(int n)
{
int k, d;
double miny = points[0].y;
int index = 0;
for(int i = 1; i < n; i++)
{
if(points[i].y < miny)
{
miny = points[i].y;
index = i;
}
else if(points[i].y == miny && points[i].x < points[index].x)
index = i;
}
point temp;
temp = points[index];
points[index] = points[0];
points[0] = temp;
qsort(points+1, n-1, sizeof(points[0]), cmp);
chs[0] = points[n-1];
chs[1] = points[0];
sp = 1;
k = 1;
while(k <= n-1)
{
double d = multi(chs[sp], chs[sp-1], points[k]);
if(d <= 0)
{
sp++;
chs[sp] = points[k];
k++;
}
else sp--;
}
}
int main()
{
double sum, d;
int T, n;
scanf("%d",&T);
for(int Ca = 1; Ca <= T; Ca++)
{
sum = 0;
scanf("%d %lf", &n, &d);
if(n == 0 || n == 1)
{
printf("Case #%d: 0.0000\n", Ca);
continue;
}
for(int i = 0; i < n; i++)
scanf("%lf%lf", &points[i].x, &points[i].y);
if(n == 2)
{
double len = dis(points[0],points[1]);
printf("Case #%d: %.4f\n", Ca, (2 * len) / (PI * d));
continue;
}
convex_hull(n);
for(int i = 1; i <= sp; i++)
sum += dis(chs[i-1], chs[i]);
sum += dis(chs[0], chs[sp]); //算出凸包周长
printf("Case #%d: %.4f\n", Ca, sum / (PI * d));
}
}

HDU 4978 A simple probability problem的更多相关文章

  1. HDU 4974 A simple water problem(贪心)

    HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...

  2. HDU 1757 A Simple Math Problem 【矩阵经典7 构造矩阵递推式】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=1757 A Simple Math Problem Time Limit: 3000/1000 MS (J ...

  3. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  4. HDU 1757 A Simple Math Problem (矩阵快速幂)

    题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...

  5. HDU 1757 A Simple Math Problem(矩阵)

    A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...

  6. HDU 1757 A Simple Math Problem (矩阵乘法)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  7. hdu 5974 A Simple Math Problem

    A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Ot ...

  8. hdu 1757 A Simple Math Problem(矩阵快速幂乘法)

    Problem Description Lele now is thinking about a simple function f(x). If x < f(x) = x. If x > ...

  9. hdu 1757 A Simple Math Problem (矩阵快速幂)

    Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 ...

随机推荐

  1. OpenReports中文支持方案

    此文章在<OpenReports中文支持完全解决方案.doc>的基础上做优化,并贴出代码.已测试通过. 一.主要解决的问题 1 页面显示支持中文 2 与服务器或数据库的交互支持中文 3 查 ...

  2. fragment的入门DEMO

    效果图: 代码如下: 1.main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  3. 使用 ETag 和 Last-Modified 报头减轻服务器压力(转)

    介绍你的网站在并发访问很大并且无法承受压力的情况下,你会选择如何优化?很多人首先会想从服务器缓存方面着手 对程序进行优化,许多不同的服务器缓存方式都有他们自己的特点,像我曾经参与的一些项目中,根据缓存 ...

  4. JS 逗号表达式

    JavaScript中逗号运算符 JavaScript中逗号运算符(,)是顺序执行两个表达式.使用方法: expression1, expression2 其中expression1是任何表达式.ex ...

  5. Android中使用shape来定义控件

    本文章转接于:http://kofi1122.blog.51cto.com/2815761/521605 Android中常常使用shape来定义控件的一些显示属性,今天看了一些shape的使用,对s ...

  6. Comparator和Comparable在排序中的应用

    http://blog.csdn.net/iisgirl/article/details/7269833

  7. Javascript的事件委托

    在谈js的事件委托之前,先来简单说说js事件的一些基础知识吧. 什么是事件?Javascipt与HTML之间的交互是通过事件实现的.事件,就是文档或浏览器中发生的一些特定的交互瞬间. 什么是事件流?事 ...

  8. 对面试题(剑指offer)产生的一些思考。

    零散的思绪.另外,推荐<剑指offer>.本文初期大部分思考都从剑指引发. 面试题不单单只是用来面试.其中有很多编程的经验可以学习.就如同我们当年的考试:) 1:鲁棒性的一个方面:边界条件 ...

  9. [原创]VS2010中创建动态链接库及其调用

    [原创]VS2010中创建动态链接库及其调用 一.创建动态链接库 在VS2010中创建动态链接库的步骤如下: 1)生成->编译->生成MyDll 二.调用 当调用DLL中的方法,程序编译产 ...

  10. YII Framework学习教程-YII的Model-开发规范-路径别名-命名空间

    到这里,大概的YII开发已经基本可以,但是下面要将的所有课程,学完之后可以让你更爱YII.下面的教程是讲的MVC的M,model.数据,业务,代码的集中地区.所以开始之前,学学开发规范-路径别名-命名 ...