uva11971 Polygon

137 篇文章 0 订阅

John has been given a segment of lenght N , however he needs a
polygon. In order to create a polygon he has cut given segment K times
at random positions (uniformly distributed cuts). Now he has K
+ 1 much shorter segments. What is the probability that he can assemble a polygon using all new segments? Input The number of tests T
( T 1000) is given on the rst line. T lines follow, each of them
contains two integers NK (1 N 10 6 ; 1 K 50) described above.
Output For each test case output a single line ` Case # T : F ‘. Where
T is the test case number (starting from 1) and F is the result as
simple fraction in form of N=D . Please refer to the sample output for
clarity.

不难发现答案只和k有关。
把问题转化成在一个圆上取k+1个点,切成k+1段,计算拼不成的概率,也就是有一段长度超过圆周一半的概率。
考虑这一段的某一个端点x,过x的直径把圆周分为两部分,如果有一段长度大于半个圆周,也就等价于剩下的k个点全在直径分成的两部分中的一个,概率为2*2^k。
点x总共有k+1种取法,每条边都被两个端点计算了两次,所以总的概率为1/2 * (k+1) * 2 * 2^k。
答案就是((1<< k)-k-1)/(1<< k)。

#include<cstdio>
#include<cstring>
#define LL long long
LL gcd(LL x,LL y)
{
    return y?gcd(y,x%y):x;
}
int main()
{
    int i,j,k,T,K=0;
    LL x,y,z;
    scanf("%d",&T);
    while (T--)
    {
        scanf("%*d%d",&k);
        x=1LL<<k;
        y=x-k-1;
        z=gcd(x,y);
        x/=z;
        y/=z;
        printf("Case #%d: %lld/%lld\n",++K,y,x);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值