标签:
题意:你懂得。
析:没什么可说的,求面积用叉乘,尽量不要用海伦公式,因为计算量大,而且精度损失。
代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #include <set> #include <vector> #include <algorithm> using namespace std; const int maxn = 100 + 5; int x[maxn], y[maxn]; int cross(int x1, int y1, int x2, int y2){ return x1 * y2 - x2 * y1; } int main(){ int n; while(scanf("%d", &n) == 1 && n){ for(int i = 0; i < n; ++i) scanf("%d %d", &x[i], &y[i]); x[n] = x[0]; y[n] = y[0]; double s = 0.0; for(int i = 0; i < n; ++i) s += cross(x[i], y[i], x[i+1], y[i+1]); printf("%.1lf\n", s/2.0); } }
标签:
原文地址:http://www.cnblogs.com/dwtfukgv/p/5634313.html