HDU 4978 A simple probability problem
A simple probability problem
Total Submission(s): 43 Accepted Submission(s): 14
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.
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.
2
2 2
-0.5 0
0.5 0
3 3
0 1
1 0
-1 0
Case #1: 0.3183
Case #2: 0.5123
题目链接 :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的更多相关文章
- HDU 4974 A simple water problem(贪心)
HDU 4974 A simple water problem pid=4974" target="_blank" style="">题目链接 ...
- 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 ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HDU 1757 A Simple Math Problem (矩阵快速幂)
题目 A Simple Math Problem 解析 矩阵快速幂模板题 构造矩阵 \[\begin{bmatrix}a_0&a_1&a_2&a_3&a_4&a ...
- HDU 1757 A Simple Math Problem(矩阵)
A Simple Math Problem [题目链接]A Simple Math Problem [题目类型]矩阵快速幂 &题解: 这是一个模板题,也算是入门了吧. 推荐一个博客:点这里 跟 ...
- HDU 1757 A Simple Math Problem (矩阵乘法)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- hdu 5974 A Simple Math Problem
A Simple Math Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- 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 > ...
- 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 ...
随机推荐
- Tcp通讯协议
了解了Udp通讯协议之后,我们再认识一个常用的通讯协议:Tcp Tcp传输特点: --依赖于Socket和ServerSocket对象 --建立客户端和服务端 --建立连接后,通过Socket中的 I ...
- 再一次强调,ORACLE外键必须加索引
外键加索引是常识,必须牢记.本来不想写这样的简单案例.可是连续遇到好几起外键不加索引导致性能问题,所以还是写一下. 一个兄弟问我 delete from Sa_Sales_Comm_Detail s ...
- 动态载入TreeView时让TreeView节点前显示加号
解释下标题,我这里通过webservice获取数据并动态载入TreeView节点.那么某个节点展开前它是没有子节点的.那么它就不显示加号.这样会让用户误以为此节点不能展开.我是这样做的,每次创建节点a ...
- [置顶] Android项目组织和代码重用
在Android应用开发过程中,只要涉及两个或以上人的开发,就需要考虑分工和代码的组织和重用问题. 代码重用有三种方式: 1.APK: 2.JAR:通过Libs/ 和Build path集成,缺点是不 ...
- Velocity知识点总结
Velocity知识点总结 1. 变量 (1)变量的定义: #set($name = "hello") 说明:velocity中变量是弱类型的. 当使用#set 指令时,括在双引號 ...
- html_day2
总结下今天学的HTML知识.单词 跑马灯标记 <marquee></marquee>属性: direction:滚动的方向 取值:left .right. up. down b ...
- alarm函数可以定时
貌似是可以的,不过感觉好像这样用不是很好,最好还是用回timer_settimer一些列函数吧,不过既然开了头,就看下alarm怎么用吧. 1. 所需头文件 #include<unistd.h ...
- MySQL 基础 之 语句执行顺序
FORM: 对FROM的左边的表和右边的表计算笛卡尔积.产生虚表VT1 ON: 对虚表VT1进行ON筛选,只有那些符合<join-condition>的行才会被记录在虚表VT2中. JOI ...
- OpenCV——Sobel和拉普拉斯变换
Sobel变换和拉普拉斯变换都是高通滤波器. 什么是高通滤波器呢?就是保留图像的高频分量(变化剧烈的部分),抑制图像的低频分量(变化缓慢的部分).而图像变化剧烈的部分,往往反应的就是图像的边沿信息了. ...
- QT TCP/IP
QT 网络通信(TCP/IP) 服务端: 一.监听新的客户端接入(QTcpServer) 重写函数 incomingConnection(qintptr socketDescriptor) 二.服务端 ...