标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 743 Accepted Submission(s): 399
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 int cmp(int a,int b){ 7 return a>b; 8 } 9 double area(int a,int b,int c){ 10 //printf("%d %d %d\n",a,b,c); 11 double q=(a+b+c)/2.0; 12 double p; 13 p=sqrt(1.0*q*(q-a)*(q-b)*(q-c)); 14 return p; 15 } 16 int stick[15]; 17 int main(){ 18 int N; 19 while(~scanf("%d",&N),N){ 20 for(int i=0;i<N;i++){ 21 scanf("%d",&stick[i]); 22 } 23 sort(stick,stick+N,cmp); 24 double ans=0; 25 for(int i=0;i+2<N;i++){ 26 if(stick[i+2]+stick[i+1]>stick[i]){ 27 ans+=area(stick[i],stick[i+1],stick[i+2]); 28 i+=2; 29 } 30 } 31 printf("%.2lf\n",ans); 32 } 33 return 0; 34 }
Little Zu Chongzhi's Triangles
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4737724.html