Lifting the Stone(求任意多边形的重心)

这篇博客探讨了如何求解多边形的重心,通过将多边形划分为多个三角形区域,并利用平面薄板重心公式,将积分转换为求和过程,从而计算出每个小三角形区域的重心,最终得出整个多边形的重心坐标。
部署运行你感兴趣的模型镜像

Lifting the Stone

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5432    Accepted Submission(s): 2273


Problem Description
There are many secret openings in the floor which are covered by a big heavy stone. When the stone is lifted up, a special mechanism detects this and activates poisoned arrows that are shot near the opening. The only possibility is to lift the stone very slowly and carefully. The ACM team must connect a rope to the stone and then lift it using a pulley. Moreover, the stone must be lifted all at once; no side can rise before another. So it is very important to find the centre of gravity and connect the rope exactly to that point. The stone has a polygonal shape and its height is the same throughout the whole polygonal area. Your task is to find the centre of gravity for the given polygon.
 

Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer N (3 <= N <= 1000000) indicating the number of points that form the polygon. This is followed by N lines, each containing two integers Xi and Yi (|Xi|, |Yi| <= 20000). These numbers are the coordinates of the i-th point. When we connect the points in the given order, we get a polygon. You may assume that the edges never touch each other (except the neighboring ones) and that they never cross. The area of the polygon is never zero, i.e. it cannot collapse into a single line.
 

Output
Print exactly one line for each test case. The line should contain exactly two numbers separated by one space. These numbers are the coordinates of the centre of gravity. Round the coordinates to the nearest number with exactly two digits after the decimal point (0.005 rounds up to 0.01). Note that the centre of gravity may be outside the polygon, if its shape is not convex. If there is such a case in the input data, print the centre anyway.
 

Sample Input
  
2 4 5 0 0 5 -5 0 0 -5 4 1 1 11 1 11 11 1 11
 

Sample Output
  
0.00 0.00 6.00 6.00
 

Source
Central Europe 1999

题意:求多边形的重心;

意解:
            定理1 已知三角形△A1A2A3的顶点坐标Ai ( xi , yi ) ( i =1, 2, 3) 。它的重心坐标为:

                   xg = (x1+x2+x3) / 3 ;                       yg = (y1+y2+y3) / 3 ;


            定理2:  将多边形划分成n个小三角形区域, 每个小区域面积为σi ,重心为Gi ( . xi , . yi ) ,利用求平面薄板重心公式把积分变
                   成累加和:

    

                           

AC代码:

          

#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

struct Point
{
    double x,y;
    Point(double x = 0, double y = 0) : x(x),y(y) {};
    void read()
    {
        scanf("%lf %lf",&x,&y);
    }
    Point operator - (const Point &a) const //重载减号;
    {
        return Point(a.x - x, a.y - y);
    }
};

double cross(Point A, Point B) //向量的叉积;
{
    return A.x * B.y - A.y * B.x;
}

double area(Point a, Point b, Point c) //三角型面积公式1/2 * cross(Point A, Point B)
{
    Point A,B;
    A = b - a;
    B = c - a;
    return cross(A,B);//不需要再除以2,因为在最后的结果中抵消了;
}

int main()
{
    int T,n;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        Point p0,p1,p2;
        double sum_x,sum_y,sum_area;
        p0.read();
        p1.read();
        sum_x = sum_y = sum_area = 0.0;
        for(int i = 2; i < n; i++)
        {
            p2.read();
            double tp = area(p0,p1,p2);
            sum_x += (p0.x + p1.x + p2.x) * tp;
            sum_y += (p0.y + p1.y + p2.y) * tp;
            sum_area += tp;
            p1 = p2;
        }
        printf("%.2lf %.2lf\n",sum_x / sum_area / 3.0, sum_y / sum_area / 3.0);
    }
    return 0;
}




  

您可能感兴趣的与本文相关的镜像

AutoGPT

AutoGPT

AI应用

AutoGPT于2023年3月30日由游戏公司Significant Gravitas Ltd.的创始人Toran Bruce Richards发布,AutoGPT是一个AI agent(智能体),也是开源的应用程序,结合了GPT-4和GPT-3.5技术,给定自然语言的目标,它将尝试通过将其分解成子任务,并在自动循环中使用互联网和其他工具来实现这一目标

LDPC码的提升矩阵(Lifting Size)在编码过程中起到了至关重要的作用。Lifting Size决定了基础矩阵的扩展程度,从而影响编码后的码字长度和码率[^2]。具体来说,通过将基础矩阵(Base Graph)与一个扩展因子(Lifting Size)结合,可以构造出扩展矩阵(Expanded Matrix),这个扩展矩阵用于对信息位进行编码。例如,对于一个基础矩阵为 $[2, 4]$ 和 Lifting Size 为 $3$ 的情况,扩展矩阵的大小为 $[2 \times 3, 4 \times 3] = [6, 12]$。 Lifting Size 的选择直接影响了码字的性能和资源占用情况。在5G NR标准中,根据基础图(Base Graph)的不同,Lifting Size 的可选范围也不同。例如,当使用基础图 BG1 时,支持的 Lifting Size 范围为 1 到 22;而当使用基础图 BG2 时,支持的 Lifting Size 范围为 1 到 10[^3]。在实际应用中,选择 Lifting Size 需要考虑码率、信道条件以及硬件资源的限制。较小的 Lifting Size 会减少编码和解码的复杂度,但可能导致码字性能下降;而较大的 Lifting Size 虽然可以提升码字性能,但会增加计算和存储需。 在5G NR标准中,Lifting Size 的选择通常是一个动态优化过程。根据输入信息的长度和所需的码率,编码器会动态选择一个合适的 Lifting Size。例如,在以下 MATLAB 函数中,`optimizeLiftingSize` 函数用于动态选择 Lifting Size: ```matlab function [encoded, params] = nrLDPCEncoder(inputBits, bgNum) % 标准化编码流程 % 输入: % inputBits - 输入比特流 % bgNum - 基图编号 % 输出: % encoded - 编码后码字 % params - 使用的编码参数 % 步骤1:码块分割 [cbSegments, numCb] = codeBlockSegment(inputBits, bgNum); % 步骤2:动态Z值选择 Z = optimizeLiftingSize(length(inputBits), bgNum); % 步骤3:各码块独立编码 encoded = []; for cb = 1:numCb encBits = encodeSingleCB(cbSegments{cb}, bgNum, Z); encoded = [encoded; encBits]; end % 返回参数 params = struct('baseGraph', bgNum, 'liftingSize', Z, ... 'codeRate', length(inputBits)/length(encoded)); end ``` 在上述代码中,`optimizeLiftingSize` 函数会根据输入信息的长度和基础图编号选择一个最优的 Lifting Size,以确保编码后的码字满足性能要[^4]。 ### 选择 Lifting Size 的方法 1. **基于基础图的限制**:首先根据基础图(BG1 或 BG2)的限制范围选择一个合适的 Lifting Size。例如,BG1 支持的 Lifting Size 范围为 1 到 22,而 BG2 支持的范围为 1 到 10。 2. **动态优化**:在实际编码过程中,可以根据输入信息的长度和所需的码率动态选择 Lifting Size。这种方法可以确保编码后的码字在特定条件下达到最佳性能。 3. **考虑资源占用**:较大的 Lifting Size 会增加编码和解码的复杂度,因此需要在性能和资源占用之间进行权衡。 综上所述,Lifting Size 的选择是一个综合考虑码率、信道条件、硬件资源和性能需的过程。在5G NR标准中,这一过程通常通过动态优化来实现,以确保编码后的码字能够在各种条件下保持良好的性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值