标签:des style blog io color ar for sp 数据
1 #include <stdio.h> 2 3 double get_area(double a,double b,double c,double d,double e,double f); 4 5 int main(){ 6 int n; 7 double x[101]; 8 double y[101]; 9 int i; 10 double total_area; 11 12 while(1){ 13 scanf("%d",&n); 14 15 if(n==0) 16 break; 17 18 total_area=0; 19 for(i=0;i<n;i++) 20 scanf("%lf%lf",&x[i],&y[i]); 21 22 for(i=0;i<n-2;i++){ //默认0,0为多边形顶点,求n-2个三角形的面积和 23 total_area+=get_area(x[0],y[0],x[i+1],y[i+1],x[i+2],y[i+2]); 24 } 25 26 printf("%.1lf\n",total_area); 27 } 28 29 return 0; 30 } 31 32 double get_area(double a,double b,double c,double d,double e,double f){ //已知三点坐标求面积 33 double area; 34 35 area=(a*d+b*e+c*f-a*f-b*c-d*e)/2; //不用加绝对值 36 37 return area; 38 }
标签:des style blog io color ar for sp 数据
原文地址:http://www.cnblogs.com/zqxLonely/p/4057902.html