Description
Input
Output
Sample Input
Sample Output
1 #include<iostream> 2 #include<cmath> 3 #include<iomanip> 4 using namespace std; 5 6 struct point 7 { 8 int x; 9 int y; 10 }; 11 12 point a[100]; 13 14 double area(point m,point n) 15 { 16 return (double)(m.x*n.y - m.y*n.x)/2; 17 } 18 19 int main() 20 { 21 int n; 22 while(cin>>n) 23 { 24 if(n==0) 25 break; 26 for(int i = 0;i<n;i++) 27 cin>>a[i].x>>a[i].y; 28 double sum = area(a[n-1],a[0]); 29 for(int i = 1;i<n;i++) 30 { 31 sum+=area(a[i-1],a[i]); 32 } 33 cout<<fixed<<setprecision(1)<<sum<<endl; 34 } 35 36 }
原文:http://www.cnblogs.com/qlky/p/4953674.html