题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2036
//C++代码
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
int n;
while(cin>>n,n){
double ans=0;
int x1,y1,x2,y2,x3,y3;
cin>>x1>>y1>>x2>>y2;
n-=2;
while(n--){
cin>>x3>>y3;
ans+=((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))/2.0;
x2=x3,y2=y3;
}
cout<<fixed<<setprecision(1)<<ans<<endl;
}
return 0;
}
本文提供了一个使用C++解决HDU 2036问题的示例代码,该问题涉及计算几何中多边形面积的算法实现。通过输入顶点坐标,程序能够计算并输出多边形的面积。
1869

被折叠的 条评论
为什么被折叠?



