zoukankan      html  css  js  c++  java
  • 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
    ",++kk,ans/(pi*d));
    96     }
    97     return 0;
    98 }
    View Code
  • 相关阅读:
    使用 python 提取照片中的手机信息
    微信域名拦截检测接口2018版本
    推荐几个Laravel 后台管理系统
    微信小程序实例源码大全
    微信开放平台开发-授权、全网发布(PHP)
    微信公众平台开发者中心安全模式消息体加解密实现
    微信开放平台搭建之EasyWeChat
    详解微信开放平台第三方平台代小程序开发业务基本接口调用逻辑
    EasyWeChat微信开放平台第三方平台接入
    身边小程序:微信门店小程序给代理加盟商的红利有哪些?
  • 原文地址:https://www.cnblogs.com/shangyu/p/3930157.html
Copyright © 2011-2022 走看看