zoukankan      html  css  js  c++  java
  • UVa 11971 Polygon (数学,转化)

    题意:一根长度为n的木条,随机选k个位置将其切成k+1段,问这k+1段能组成k+1条边的多边形的概率。

    析:这个题,很明显和 n 是没有任何关系的,因为无论 n 是多少那切多少段都可以,只与切多少段有关。然后我们要转化一下,不能直接做,因为不好做。

    转化为一个圆上选 m+1 个点,能不能组成多边形,很容易知道如果一个边大于一半圆的周长,那就组不成多边形。然后位置是随便选的,概率就是1,

    然后其他 m-1 个点,就只能放那一半上,每个都有1/2的概率,然后 m 个,就是1/(2^m),然后每个点都可能是最长的,所以再乘以(m+1),

    这是组不成的概率,然后用总概率1减去,就是组成的概率。注意long long,刚开始忘了,WA了一次。

    代码如下:

    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <cstdio>
    #include <string>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    #include <cstring>
    #include <set>
    #include <queue>
    #include <algorithm>
    #include <vector>
    #include <map>
    #include <cctype>
    using namespace std ;
    
    typedef long long LL;
    typedef pair<int, int> P;
    const int INF = 0x3f3f3f3f;
    const double inf = 0x3f3f3f3f3f3f3f;
    const double eps = 1e-8;
    const int maxn = 1e4 + 5;
    const int mod = 1e9 + 7;
    const int dr[] = {0, 0, -1, 1};
    const int dc[] = {-1, 1, 0, 0};
    int n, m;
    inline bool is_in(int r, int c){
        return r >= 0 && r < n && c >= 0 && c < m;
    }
    
    int main(){
        int T;  cin >> T;
        for(int kase = 1; kase <= T; ++kase){
            scanf("%d %d", &n, &m);
            LL a = m + 1;
            LL b = 1LL<<m;
            LL c = b - a;
            LL g = __gcd(c, b);
            printf("Case #%d: %lld/%lld
    ", kase, c / g, b / g);
        }
        return 0;
    }
    
  • 相关阅读:
    CF1187E Tree Painting
    [TJOI2017]城市
    [HNOI2010]合唱队
    2020暑假多校补题记录
    树形dp总结
    2017CCPC 秦皇岛 G. Numbers (贪心 + java大数)
    LOJ 2491 求和 (LCA + 前缀和)
    LOJ 10105. 欧拉回路
    Luogu P3953 逛公园 (最短路+dp)
    LOJ#2718. 「NOI2018」归程 (kruskal重构树)
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5746826.html
Copyright © 2011-2022 走看看