[题] 改革春风吹满地 #图论 #多边形面积

题目

HDU 2036 改革春风吹满地

题解

参考博客:HDU 2036 改革春风吹满地

代码

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
//叉乘计算面积的公式,以(0,0)为起始点划分
int main() {
	int n;
    while(~scanf("%d", &n) && n) {
    	double sum = 0, x[N], y[N];
        for(int i = 1; i <= n; i ++) {
        	scanf("%lf%lf", &x[i], &y[i]);
        	if(i > 1)
        		sum += x[i - 1] * y[i] - x[i] * y[i - 1];
		}
        sum += x[n] * y[1] - x[1] * y[n];
        printf("%.1lf\n", 0.5 * sum);
    }
    return 0;
}
相关推荐
Lazionr21 分钟前
多态:从多种形态到运行时绑定
开发语言·c++
tryxr28 分钟前
矩阵的几种基础变换
java·数据结构·算法·矩阵
mmmmath_332 分钟前
LeetCode.028.找出字符串中第一个匹配项的
数据结构·算法·leetcode
别动我齐刘海32 分钟前
ROS2 Jazzy + C++ 实战路线——ros2_control
c++·人工智能·python·opencv·机器学习·机器人·github
Selvaggia42 分钟前
DMD(Distribution Matching Distillation,分布匹配蒸馏)
算法
Navigator_Z1 小时前
LeetCode //C - 1255. Maximum Score Words Formed by Letters
c语言·算法·leetcode
All for pursuit.1 小时前
【栈-4】739.每日温度
数据结构·c++·算法·leetcode
码匠许师傅1 小时前
【C++三方组件】glog:Google 出品的 C++ 日志库
c++
Lazionr1 小时前
二叉搜索树:从树形结构到高效查找
开发语言·c++
此生决int1 小时前
深入理解C++系列(21)——异常
开发语言·c++