Hdu4987a simple probability problem. (convex hull)

Source: Internet
Author: User
Tags mul

Link

In the last session of multiple schools, I didn't understand the meaning of the question at the time. I thought it was a probability problem and I didn't have to look into it.

Official question

For the first one he said, considering that the probability of a line segment with a length of L is 2L/(pI * D), we can understand that we do not know what we are talking about ..

According to my initial idea, I want to enumerate the angle and calculate the probability based on the height difference of the convex hull. However, there is a simpler way to find the perimeter of the convex hull in the question. In this way, I understand that, the probability of a line in a convex hull passing through a straight line is as 2L/(pI * d) As mentioned above. However, because he is a polygon, there must be a forward line, so passing through a line segment is equivalent to passing through two lines. The whole is/2... I don't know if this method is correct.

 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 11112 #define LL long long13 #define INF 0xfffffff14 const double eps = 1e-8;15 const double pi = acos(-1.0);16 const double inf = ~0u>>2;17 struct point18 {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     else49         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 }
View code

 

Hdu4987a simple probability problem. (convex hull)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.