UVA - 11971 Polygon

探讨了给定长度的线段通过特定次数切割后能够构成多边形的概率问题,并提供了一种有效的数学方法和C++实现代码来解决该问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接  http://acm.hust.edu.cn/vjudge/problem/22851

题目大意:给定一个长度为N的线段,要求切K刀,
    分成K+1个线段,问能组成K+1边形的概率。

K条线段能组成K边形的条件为任意一条边小于其他所有边的和,
因为是求概率,所以和N无关。
注意范围 都用的long long 

将木条围成一个圆后再开切k+1刀,得到k+1段。
第一个点随机选,概率为1,假设这个点就是木条要组成圆的那两端。
接下来要选其他的k个点的位置,他们都在同一个半圆上的概率是(1/2)k。
假设分成这样的k+1段,A0A1A2....AK。那么A0--A1就是一段了。
假设是这一段最大且超过n的一半。
那么其他的k-1个位置就必须在同一边且在偏短的那一边。
共有k+1段,都有可能是最长的那段,所以概率(k+1)*(1/2)k。
答案为1-(k+1)*(1/2)k。
(摘自网上的)


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define INF 0x3f3f3f3f
using namespace std;
typedef pair<int, int> P;
const int maxn = 1e5 + 5;

LL gcd(LL a, LL b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
int main(void)
{
//	freopen("C:\\Users\\wave\\Desktop\\NULL.exe\\NULL\\in.txt","r", stdin);
    LL n, k;
    int T, cas = 1;
    cin >> T;
    while (T--){
        scanf("%lld %lld", &n, &k);
        LL a = ((LL)1<<k) - (k+1);  // 要在 (1<<k) 里面强制转换(LL)  不然会爆 
        LL b = ((LL)1<<k);
        LL t = gcd(a, b);
        a /= t;
        b /= t;
        if (k == 1)
            printf("Case #%d: 0/1\n", cas++);
        else printf("Case #%d: %lld/%lld\n", cas++, a, b);
    }

    return 0;
}


### No-Fit Polygon概念及其算法实现 No-Fit Polygon (NFP) 是计算几何中的一个重要概念,主要用于解决多边形布局优化问题。当两个多边形之间存在相对位置关系时,NFP 描述了一个多边形相对于另一个多边形无法放置的区域。 #### NFP 的定义 对于任意给定的一对多边形 A 和 B,在平面上移动其中一个(比如 B),使得这两个图形不重叠的情况下,B 所能占据的空间范围构成了一个虚拟边界——即所谓的 "No Fit Polygon"[^3]。 #### 计算方法概述 为了构建 no-fit 多边形,通常采用以下几种策略: 1. **基于线段的方法** 这种方式通过分析两对象边缘上的每一对相邻顶点形成的向量来确定接触条件下的极限情况。具体来说就是找到所有可能造成碰撞的位置并记录下来形成新的轮廓线。 2. **Minkowski Sum 方法** 利用 Minkowski 差集运算可以有效地求解复杂形状间的无冲突配置空间。该过程涉及将一个多边形沿另一固定物体表面滑动,并收集所有的触碰事件以建立最终的结果边界。 ```python def compute_minkowski_difference(A, B): """ Computes the minkowski difference between two polygons. Args: A(list): List of points representing first polygon [(x,y), ...] B(list): List of points representing second polygon Returns: list: Points that form the boundary of the resulting shape after performing minkowski sum operation on input shapes. """ result = [] for a_point in A: for b_point in B: diff_x = a_point[0] - b_point[0] diff_y = a_point[1] - b_point[1] result.append((diff_x, diff_y)) # Simplify and sort the output to get proper contour representation simplified_result = simplify_polygon(result) sorted_contour = order_points_clockwise(simplified_result) return sorted_contour ``` 上述代码片段展示了如何利用 Python 实现简单的 Minkowski Difference 函数用于生成 no-fit 多边形的基础框架。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值