Polygon UVA - 11971

题解:如果只是在长木棍时操作,有点不太好想。假如看作一个圆,切 k+1 次,问能组成多边形的概率?从反面考虑,不能组成多边形的概率。

当切出的一部份长度超过圆的1/2时,肯定不能组成多边形,即有k个点在半圆上,概率为 1/ 2k ,而第一个点有k+1种取法,所以不能组成的概

率为 (k+1)/2k。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 int n,k,kase;
 9 
10 ll gcd(ll a,ll b){
11     if(b==0) return a;
12     return gcd(b,a%b);
13 }
14 
15 void solve(int t){
16     ll temp=1;
17     for(int i=1;i<=k;i++) temp=temp*2;
18     ll temp2=gcd(temp-k-1,temp);
19     printf("Case #%d: %lld/%lld\n",t,(temp-k-1)/temp2,temp/temp2);
20 }
21 
22 int main()
23 {   cin>>kase;
24     for(int t=1;t<=kase;t++){
25         cin>>n>>k;
26         solve(t);
27     }
28     return 0;
29 }

 

转载于:https://www.cnblogs.com/zgglj-com/p/7360753.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值