• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
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\n", kase, c / g, b / g);
    }
    return 0;
}

 

posted on 2016-08-07 18:30  dwtfukgv  阅读(459)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3