1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| #include <bits/stdc++.h> using namespace std;
struct point{ double x; double y; };
int main(){ int n; cin>>n; point p[n]; for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y; double a = 0.0; for(int i=0;i<n;i++){ if(i==n-1){ a+=(p[i].x)*(p[0].y)-(p[0].x)*(p[i].y); } else{ a+=(p[i].x)*(p[i+1].y)-(p[i+1].x)*(p[i].y); } } a = abs(a/2); cout<<fixed<<setprecision(2)<<a<<endl; }
|