zoukankan      html  css  js  c++  java
  • 多边形的面积

    多边形的面积

    时间限制: 1 Sec  内存限制: 128 MB
    提交: 145  解决: 32
    [提交][状态][讨论版]

    题目描述

    给出一个简单多边形(没有缺口),它的边要么是垂直的,要么是水平的。要求计算多边形的面积。

    多边形被放置在一个X-Y的卡笛尔平面上,它所有的边都平行于两条坐标轴之一。然后按逆时针方向给出各顶点的坐标值。所有的坐标值都是整数(因此多边形的面积也为整数)。

    输入

    第 一行给出多边形的顶点数n(n≤100)。接下来的几行每行给出多边形一个顶点的坐标值x和y(都为整数并且用空格隔开)。顶点按逆时针方向逐个给出。并 且多边形的每一个顶点的坐标值-200≤x,y≤200。多边形最后是靠从最后一个顶点到第一个顶点画一条边来封闭的。

    输出

    仅有一行包含一个整数,表示多边形的面积。

    样例输入

    10
    0 0
    4 0
    4 1
    3 1
    3 3
    2 3
    2 2
    1 2
    1 3
    0 3
    

    样例输出

    9
    
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <algorithm>
    #include <climits>
    #include <cstring>
    #include <string>
    #include <set>
    #include <map>
    #include <queue>
    #include <stack>
    #include <vector>
    #include <list>
    #include<functional>
    #define mod 1000000007
    #define inf 0x3f3f3f3f
    #define pi acos(-1.0)
    using namespace std;
    typedef long long ll;
    const int N=205;
    const int M=15005;
     
    int n,m;
    int a[N],dp[N];
    int x[N],y[N];
    int main(){
        int s=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d%d",&x[i],&y[i]);
        }
        x[n+1]=x[1];y[n+1]=y[1];
        for(int i=1;i<=n;i++){
           s+=x[i]*y[i+1]-x[i+1]*y[i];
        }
        s=abs(s);
        cout<<s/2<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    前端开发小结(持续更新)
    UDP 通讯及内部分析(合集)
    困扰我三天的问题
    Clang Format Style Options (.clang-format 配置文件文档)
    关于共享库的那些事儿
    如何在VMWare的NAT模式下使用traceroute(解析vmnat的行为)
    Linux网络配置
    Ansible Ad-Hoc命令集
    Ansible基础使用
    Ansible部署及配置介绍
  • 原文地址:https://www.cnblogs.com/jianrenfang/p/5789070.html
Copyright © 2011-2022 走看看