hdu2036

来源:互联网 发布:软件行业会计处理 编辑:程序博客网 时间:2024/06/05 20:03

利用叉乘的性质来求面积!

#include <iostream>#include <cstring>#include <iomanip>using namespace std;const int MAXN = 110;struct Node{int x, y;};double Cross_Product(Node a, Node b, Node c){return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);}int main(){int n;Node nodes[MAXN];int i;while (cin>>n && n){double sum  = 0;for (i = 0; i < n; ++i){cin>>nodes[i].x>>nodes[i].y;}for (i = 1; i < n-1; ++i){sum += Cross_Product(nodes[0], nodes[i], nodes[i+1]);}cout<<fixed<<setprecision(1)<<sum/2<<endl;}return 0;}


0 0
原创粉丝点击