Test instructions: a circle with a diameter of D has n points, each two points with a line connection, a plane with a space of d parallel lines, the original placed on the plane at least one line segment and parallel intersection of the probability;
Ideas:
what needle problem; http://wenku.baidu.com/link?url= S3rjrguhcz7kmsxa6o7edr8h1rjjbibu2ocs1yf5bpspwskjkk9w-uvsv4d-cbgv36ua9bpxvfqlla9qlpwbwkybjkfzdap_n5dtwhvt_mi
The probability of the intersection of a needle with a length of L and a parallel line spaced D is p=2*l/(PI*D);
The probability of intersection of a convex n-shaped parallel line with a spacing of D is p=c/(pi*d);(C is a convex n-shaped perimeter);
The convex Bao Zhouchang required by the subject, the result is the circumference divided by (π multiplied by the diameter);
Examples run out of the same, geometric problems is so magical ...
#include <cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespacestd;Const Doubleepsi=1e-Ten;Const DoublePi=acos (-1.0);Const intmaxn=10005;structpoint{Doublex, y; Point () {}, point (DoubleXxDoubleyy): X (xx), Y (yy) {} pointoperator-(ConstPoint &op2)Const{ returnPoint (x-op2.x,y-op2.y); } Double operator^(ConstPoint &op2)Const{//Cross product of two point vectors returnx*op2.y-y*op2.x; }};inlineintSignConst Double&x) { if(X>EPSI)return 1; if(X<-EPSI)return-1; return 0;} InlineDoubleSqrConst Double&x) { returnx*x;} InlineDoubleMulConstPoint &p0,ConstPoint &p1,ConstPoint &p2) { return(p1-p0) ^ (p2-p0);} InlineDoubleDis2 (ConstPoint &p0,ConstPoint &p1) { returnSqr (p0.x-p1.x) +SQR (p0.y-p1.y);} InlineDoubleDisConstPoint &p0,ConstPoint &p1) { returnsqrt (Dis2 (P0,P1));}intn,l;//n vertices, nearest distance is LPoint P[maxn],convex_hull;//The polygon vertex sequence is p[], and the lowest position is Convex_hull .InlineBOOLcmpConstPoint &a,ConstPoint &b) {//relative lows, point angles from small to large, distance from near to far sort returnSign (Mul (convex_hull,a,b)) >0|| Sign (Mul (convex_hull,a,b)) = =0&&dis2 (Convex_hull,a) <Dis2 (convex_hull,b);}intConvex (Point *a,intN,point *b) {//calculating the convex hull B of point set A with n points if(n<3) printf ("wrong in line%d\n", __line__);//number of vertices less than 3, output failure information for(intI=1; i<n;i++)//calculate the lowest convex_hull if(Sign (a[i].x-a[0].x) <0|| Sign (a[i].x-a[0].x) = =0&&sign (a[i].y-a[0].Y) <0) Swap (a[0],a[i]); Convex_hull=a[0]; Sort (A,a+N,CMP);//Sort by polar angle and distance intnewn=2; b[0]=a[0];b[1]=a[1];//a[0],a[1] into the stack for(intI=2; i<n;i++){ while(newn>1&&sign (Mul (b[newn-1],b[newn-2],a[i]) >=0)--newn;//pop-up stack top all the elements that are not left-pointing to scan vertex iB[newn++]=a[i];//vertex i into the stack } returnnewn;//stack Top pointer}intMain () {intT,cas; scanf ("%d",&t); for(cas=1; cas<=t;cas++) {scanf ("%d%d",&n,&l); for(intI=0; i<n;i++) scanf ("%LF%LF",&p[i].x,&p[i].y); printf ("Case #%d:", CAs); if(n>2) {n=convex (p,n,p); P[n]=p[0];//Connected Doubleans=0; for(intI=0; i<n;i++) ans+=dis (p[i],p[i+1]);//Cumulative convex edge length//ans+=2*pi*l;printf"%.4lf\n", ans/(pi*l)); } Else if(n==2) { DoubleAns=dis (p[0],p[1]); printf ("%.4lf\n",2*ans/(pi*l)); } Elseprintf ("0.0000\n"); } return 0;}
HDU 4978 A simple probability problem. (Probabilistic model + convex Bao Zhouchang)