uva 11971 Polygon 连续概率

来源:互联网 发布:java web源代码下载 编辑:程序博客网 时间:2024/05/16 14:12
  1. 都随机的点要通过假设先定下来,要考虑到假设时这种情况发生的种类数。
  2. 找到题意要求满足多边形的核心条件。

题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=229&page=show_problem&problem=3122

题解:把这段木条想象成一个圆,不能构成一个多边形的条件是有一条边大于等于这个木条的一半,而我们假设一个一个点随机选取,那么假设第i个点开始半周内不能有点,那么其它k个点都要在另一半,即1/2^k,而一共有k+1个点可供选择,所以最后结论就是1-(k+1)/2^k

#include<cstdio>#include<iostream>#include<sstream>#include<cstdlib>#include<cmath>#include<cctype>#include<string>#include<cstring>#include<algorithm>#include<stack>#include<queue>#include<set>#include<map>#include<ctime>#include<vector>#include<fstream>#include<list>using namespace std;#define ms(s) memset(s,0,sizeof(s))typedef unsigned long long ULL;typedef long long LL;const int INF = 0x3fffffff;LL gcd(LL a, LL b){  return (b==0) ? a : gcd(b,a%b);}int main(){//    freopen("F:\\input.txt","r",stdin);//    freopen("F:\\output.txt","w",stdout);//    ios::sync_with_stdio(false);    int t;    LL n,k;    scanf("%d",&t);    LL a,b;    LL gcdd;    for(int cas = 1; cas <= t; ++cas){        scanf("%lld%lld",&n,&k);        a = pow(2,k);        b = a;        a = a-k-1;        gcdd = gcd(a,b);        a /= gcdd;        b /= gcdd;        printf("Case #%d: %lld/%lld\n",cas,a,b);    }    return 0;}
1 0