zoukankan      html  css  js  c++  java
  • [poj] 3907 Build Your Home || 求多边形面积

    原题

    多组数据,到0为止。
    每次给出按顺序的n个点(可能逆时针,可能顺时针),求多边形面积(保留整数)


    多边形面积为依次每条边(向量)叉积/2的和
    (S=sum _{i=1}^{n-1}p[i]*p[i+1]/2)
    //逆时针为正,顺时针为负

    #include<cstdio>
    #define N 1010
    using namespace std;
    int n;
    struct hhh
    {
        double x,y;
        hhh() {}
        hhh(double _x,double _y) : x(_x),y(_y) {}
        double operator * (const hhh &b) const
    	{
    	    return x*b.y-b.x*y;
    	}
    }p[N];
    
    double Area()
    {
        double ans=0;
        for (int i=2;i<=n;i++)
    	ans+=(p[i-1]*p[i])/2;
        ans+=(p[n]*p[1])/2;
        return ans;
    }
    
    double abs(double x) { return x>=0?x:-x; }
    
    int main()
    {
        while (~scanf("%d",&n) && n)
        {
    	for (int i=1;i<=n;i++)
    	    scanf("%lf%lf",&p[i].x,&p[i].y);
    	printf("%.f
    ",abs(Area()));
        }
        return 0;
    }
    
  • 相关阅读:
    Excel VB Script
    Excel Text Converter as C# Format
    快捷键
    如何使用 MasterPage
    Excel 오른쪽버튼 윗주
    Oracle Hints
    ASP.NET 弹出窗口
    Log4Net
    word 修改 表宽度
    While 나가는 법
  • 原文地址:https://www.cnblogs.com/mrha/p/8066976.html
Copyright © 2011-2022 走看看