zoukankan      html  css  js  c++  java
  • hoj2036

    求多边形面积,选定(0,0)点,用三角形法求,求三角形面积时用叉积,把式子展开并合并同类项可得模板中的公式。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define maxn 101

    struct XPoint
    {
    double x, y;
    }point[maxn];

    int n;

    void input()
    {
    for (int i = 0; i < n; i++)
    {
    scanf(
    "%lf%lf", &point[i].x, &point[i].y);
    }
    }

    double areaofp(int vcount, XPoint plg[])
    {
    int i;
    double s;
    if (vcount<3) return 0;
    s
    =plg[0].y*(plg[vcount-1].x-plg[1].x);
    for (i=1;i<vcount;i++)
    s
    +=plg[i].y*(plg[(i-1)].x-plg[(i+1)%vcount].x);
    return s/2;
    }

    int main()
    {
    //freopen("D:\\t.txt", "r", stdin);
    while (scanf("%d", &n) != EOF && n != 0)
    {
    input();
    printf(
    "%.1f\n", areaofp(n, point));
    }
    return 0;
    }
  • 相关阅读:
    简单状态机
    c语言状态机
    存储公司
    正确跑步
    好好做自己能做的
    I2C学习
    es6 generator函数
    es6 for of 循环
    es6 proxy代理
    es6 Symbol类型
  • 原文地址:https://www.cnblogs.com/rainydays/p/1999140.html
Copyright © 2011-2022 走看看