nyist 67三角形面積

來源:互聯網
上載者:User

標籤:os   io   資料   ar   amp   時間   ios   on   

三角形面積
時間限制:3000 ms | 記憶體限制:65535 KB
難度:2
描述
給你三個點,表示一個三角形的三個頂點,現你的任務是求出該三角形的面積
輸入
每行是一組測試資料,有6個整數x1,y1,x2,y2,x3,y3分別表示三個點的橫縱座標。(座標值都在0到10000之間)
輸入0 0 0 0 0 0表示輸入結束
測試資料不超過10000組
輸出
輸出這三個點所代表的三角形的面積,結果精確到小數點後1位(即使是整數也要輸出一位小數位)
範例輸入
0 0 1 1 1 3
0 1 1 0 0 0
0 0 0 0 0 0範例輸出
1.0
0.5

 

 

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c,d,e,r,s;
while(1)
{
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&r);
if(a==0&&b==0&&c==0&&d==0&&e==0&&r==0) return 0;

s=(a*d+b*e+c*r)-(a*r+d*e+b*c);
if(s<0) s=-s;
printf("%.1f\n",s/2.0);

}
return 0;
}


************************************************************************************************

 


#include<stdio.h> //68 nyist
#include<math.h>
main()
{
int x0,x1,x2,y0,y1,y2;
double s;
while(scanf("%d%d%d%d%d%d",&x0,&y0,&x1,&y1,&x2,&y2))
{
if(x0==0&&y0==0&&x1==0&&y1==0&&x2==0&&y2==0) break;
s=((x1-x0)*(y2-y0)-(x2-x0)*(y1-y0))/2.0;
if(s>=0)
printf("0\n");
else
printf("1\n");
}
}


************************************************************************

 

 

//海倫公式

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int x1,x2,x3,y1,y2,y3;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
{
if(x1==0&&x2==0&&x3==0&&y1==0&&y2==0&&y3==0) break;
double a,b,c,p,s;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
p=(a+b+c)/2;
printf("%.1f\n",sqrt(p*(p-a)*(p-b)*(p-c)));

}
return 0;
}

 

 

 

 

#include<stdio.h>
#include<math.h>
int main()
{
int x1,x2,x3,y1,y2,y3;
while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
{
if(x1==0&&x2==0&&x3==0&&y1==0&&y2==0&&y3==0) break;
double a,b,c,p,s;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
c=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
p=(a+b+c)/2;
printf("%.1f\n",sqrt(p*(p-a)*(p-b)*(p-c)));
}
return 0;
}

 

 

 

 

 


#include<stdio.h>
#include<math.h>
main()
{
int x1,x2,x3,y1,y2,y3,m;
double a,b,c,s,area;
scanf("%d",&m);
while(m--)
{
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
if(x1==0&&y1==0&&x2==0&&y2==0&&x3==0&&y3==0)
continue;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
s=1.0/2*(a+b+c);
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("%.1f\n",area);
}
}

 

 

 

 

#include<stdio.h>
#include<math.h>
int main()
{
int x1,y1,x2,y2,x3,y3;
while(scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF&&(x1!=0||x2!=0||x3!=0||y1!=0||y2!=0||y3!=0))
{
double l1,l2,l3,p,s;
l1=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
l2=sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3));
l3=sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3));
p=(l1+l2+l3)/2;
s=sqrt(p*(p-l1)*(p-l2)*(p-l3));
printf("%.1f\n",s);
}
return 0;
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.