题目链接 http://lightoj.com/volume_showproblem.php?problem=1305
题意:已知平行四边形三点坐标求第四点及面积。
注意:“%.0lf'"配合double型是四舍五入的;int型=double型是去尾法保留,需+0.5才是四舍五入。
#include <stdio.h>
#include <math.h>
void Deal ()
{
int ax,ay,bx,by,cx,cy,dx,dy;
scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy);
dx=cx-(bx-ax);
dy=cy-(by-ay);
int ab2=(bx-ax)*(bx-ax)+(by-ay)*(by-ay);
int bc2=(bx-cx)*(bx-cx)+(by-cy)*(by-cy);
int ac2=(cx-ax)*(cx-ax)+(cy-ay)*(cy-ay);
double alpha=acos(1.0*(ab2+bc2-ac2)/(2*sqrt(ab2)*sqrt(bc2)));
// double s=sqrt(ab2)*sqrt(bc2)*sin(alpha); //两种输出方法
// printf("%d %d %.0lf\n",dx,dy,s);
int s=sqrt(ab2)*sqrt(bc2)*sin(alpha)+0.5;
printf("%d %d %d\n",dx,dy,s);
}
int main ()
{
int T;
scanf("%d",&T);
for (int cas=1;cas<=T;cas++)
printf("Case %d: ",cas),Deal();
return 0;
}
/*
Input:
2
-751 -237 -13 926 650 -570
-776 -677 -999 861 555 -762
Output:
Case 1: -88 -1733 1875117
Case 2: 778 -2300 2028123
*/