zoukankan      html  css  js  c++  java
  • hdu2036(改革春风吹满地)

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <vector>
    using namespace std;
    const int maxn = 110;
    
    struct Point{
        double x, y;
        Point(double x = 0, double y = 0):x(x), y(y) { }
    };
    
    typedef Point Vector;
    Vector v[maxn];
    
    double Cross(Vector A, Vector B) {
        return A.x * B.y - A.y * B.x;
    }
    
    Vector operator - (Point A, Point B) {
        return Vector(A.x-B.x, A.y-B.y);
    }
    
    double getArea(Point* p, int n) {
        double area = 0;
        for(int i = 1; i < n-1; i++) {
            area += Cross(p[i]-p[0], p[i+1]-p[0]);
        }
        return area/2;
    }
    
    int main()
    {
        int n;
        int x, y;
        while(scanf("%d", &n)!=EOF) {
            if(n==0) break;
            for(int i = 0; i < n; i++){
                scanf("%d%d", &x, &y);
                v[i] = Point(x, y);
            }
            double res = getArea(v, n);
            printf("%.1lf\n", res);
        }
        return 0;
    }
    


  • 相关阅读:
    P1158 导弹拦截
    麦基数(p1045)
    Django之路由层
    web应用与http协议
    Django之简介
    Mysql之表的查询
    Mysql之完整性约束
    Mysql之常用操作
    Mysql之数据类型
    Mysql之数据库简介
  • 原文地址:https://www.cnblogs.com/javawebsoa/p/3055247.html
Copyright © 2011-2022 走看看