hdu4987A simple probability problem.(凸包)

链接

多校的最后一场,当时没看懂题意,看题目还以为是概率问题就没深看。

官方题解

对于他说的第一种,考虑长为L的线段 概率为2L/(pi*d), 可以理解,下面的就不知道在说啥了。。

按我初始的想法想要枚举角度,根据凸包的高度差得出概率,不过有一种更简便的方式,就是题解中的求出凸包的周长,这种方式我的理解为,凸包中的一条线段穿过直线的概率就跟上面所说的线段一样2L/(pi*d),不过因为他是个多边形,有进就肯定有出,所以穿过一条线段就相当于穿过两条,整体来说就是/2...不知道这种理解方式对不对

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<vector>
 7 #include<cmath>
 8 #include<queue>
 9 #include<set>
10 using namespace std;
11 #define N 111
12 #define LL long long
13 #define INF 0xfffffff
14 const double eps = 1e-8;
15 const double pi = acos(-1.0);
16 const double inf = ~0u>>2;
17 struct point
18 {
19     double x,y;
20     point(double x=0,double y =0 ):x(x),y(y){}
21 }p[N],ch[N];
22 typedef point pointt;
23 point operator -(point a,point b)
24 {
25     return point(a.x-b.x,a.y-b.y);
26 }
27 double cross(point a,point b)
28 {
29     return a.x*b.y-a.y*b.x;
30 }
31 int dcmp(double x)
32 {
33     if(fabs(x)<eps) return 0;
34      else return x<0?-1:1;
35 }
36 double mul(point p0,point p1,point p2)
37 {
38     return cross(p1-p0,p2-p0);
39 }
40 double dis(point a)
41 {
42     return sqrt(a.x*a.x+a.y*a.y);
43 }
44 bool cmp(point a,point b)
45 {
46     if(dcmp(mul(p[0],a,b))==0)
47         return dis(a-p[0])<dis(b-p[0]);
48     else
49         return dcmp(mul(p[0],a,b))>0;
50 }
51 int Graham(int n)
52 {
53     int i,k = 0,top;
54     point tmp;
55     for(i = 0 ; i < n; i++)
56     {
57         if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))
58             k = i;
59     }
60     if(k!=0)
61     {
62         tmp = p[0];
63         p[0] = p[k];
64         p[k] = tmp;
65     }
66     sort(p+1,p+n,cmp);
67     ch[0] = p[0];
68     ch[1] = p[1];
69     top = 1;
70     for(i = 2; i < n ; i++)
71     {
72         while(top>0&&dcmp(mul(ch[top-1],ch[top],p[i]))<0)
73             top--;
74         top++;
75         ch[top] = p[i];
76     }
77     return top;
78 }
79
80 int main()
81 {
82     int t,i,n,d;
83     int kk =0 ;
84     cin>>t;
85     while(t--)
86     {
87         scanf("%d%d",&n,&d);
88         for(i =0 ; i < n;  i++)
89         scanf("%lf%lf",&p[i].x,&p[i].y);
90         int m = Graham(n);
91         ch[m+1] = ch[0];
92         double ans =0 ;
93         for(i = 0 ; i <= m ; i++)
94         ans += dis(ch[i]-ch[i+1]);
95         printf("Case #%d: %.4f\n",++kk,ans/(pi*d));
96     }
97     return 0;
98 }

时间: 2024-10-21 03:49:13

hdu4987A simple probability problem.(凸包)的相关文章

HDU 4978 A simple probability problem

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 sep

HDU 4978 A simple probability problem 【凸包】【几何】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4978 题目大意:给你在平面上一些平行的线,线之间的距离是D,然后在给你一些不共线的点,每两点之间都有线相连,现在问这些点连成的线与平面上平行的线相交的概率. 这里要先介绍一个模型:蒲丰投针问题 知道了这个模型之后我们就能解决只有两个点的问题了,P=2L/πD (L为针长,D为平行线间距) 但是给出的是有很多个点,所以我们还要知道蒲丰投针问题扩展,将给出的点构造成一个凸包,若是凸包内部的线可以和平面上

HDU 4978 A simple probability problem.(概率模型+凸包周长)

题意:一个直径为d的圆中有n个点,每两点间有线段连接,一个平面上有间距都为d的平行线,求将原放在该平面上至少有一条线段与平行线相交的概率: 思路: 蒲丰针问题:http://wenku.baidu.com/link?url=s3rJRGUhCZ7kmsXA6o7Edr8h1rJJbibu2Ocs1Yf5BpsPwSkjkK9w-uVSV4d-cBGV36UA9bpxVfqLLA9qlPwbWkYbjkFzDaP_N5dtWHVT_mi 长度为L的针与间距为d的平行线相交的概率为P=2*L/(pi

BNU 28887——A Simple Tree Problem——————【将多子树转化成线段树+区间更新】

A Simple Tree Problem Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on ZJU. Original ID: 368664-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Discuss Next Type: None None Graph Theory 2-SA

hdu 4974 A simple water problem(数学题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4974 Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or

A Simple Math Problem(矩阵快速幂)(寒假闭关第一题,有点曲折啊)

A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 155 Accepted Submission(s): 110   Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x.If

hdu1757-- A Simple Math Problem(矩阵快速幂优化)

A Simple Math Problem Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * f(x-1) + a1 * f(x-2) + a2

HDU 4974 A simple water problem(贪心)

HDU 4974 A simple water problem 题目链接 签到题,很容易贪心得到答案是(sum + 1) / 2和ai最大值的最大值 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int N = 100005; typedef long long ll; int t, n; ll a, Max, sum; int main(

HDU - 4974 A simple water problem

Problem Description Dragon is watching competitions on TV. Every competition is held between two competitors, and surely Dragon's favorite. After each competition he will give a score of either 0 or 1 for each competitor and add it to the total score