zoukankan      html  css  js  c++  java
  • HDU1115&&POJ1385Lifting the Stone(求多边形的重心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115#

    大意:给你个n,有n个点,然后给你n个点的坐标,求这n个点形成的多边形的重心的坐标。

    直接套模板,我也不知道什么意思。注意在POJ上面定义double时,输出f,如果输出lf则WA,HDU上面输出lf能A。

    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <algorithm>
    #include <math.h>
    #include <queue>
    #define inf 0x3f3f3f3f
    #define eps 1e-9
    typedef long long ll;
    using namespace std;
    int n;
    struct Point
    {
        double x,y;
    } q[1000010];
    double cross(Point a,Point b)
    {
        return a.x*b.y-a.y*b.x;
    }
    Point interity(Point p[],int n)
    {
        Point inter= {0,0};
        double area=0;
        for(int i=0; i<n; i++)
        {
            double tmp=cross(p[i],p[(i+1)%n]);
            inter.x+=tmp*(p[i].x+p[(i+1)%n].x);
            inter.y+=tmp*(p[i].y+p[(i+1)%n].y);
            area+=tmp;
        }
        inter.x/=3*area;
        inter.y/=3*area;
        return inter;
    }
    int main()
    {
        int T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            for(int i=0; i<n; i++)
            {
                scanf("%lf%lf",&q[i].x,&q[i].y);
            }
            Point temp=interity(q,n);
            printf("%.2f %.2f
    ",temp.x,temp.y);
        }
        return 0;
    }
  • 相关阅读:
    Docker 私有仓库高级配置
    Docker 私有仓库
    Docker Hub
    访问 Docker 仓库
    Docker 删除容器
    392. 判断子序列
    605. 种花问题
    122. 买卖股票的最佳时机 II
    121. 买卖股票的最佳时机
    406. 根据身高重建队列
  • 原文地址:https://www.cnblogs.com/zhangmingcheng/p/4277919.html
Copyright © 2011-2022 走看看