LightOJ 1305 - Area of a Parallelogram(数学啊 )
2015-03-29 09:51
459 查看
题目链接:http://lightoj.com/volume_showproblem.php?problem=1305
A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:
Fig: a parallelogram
Now you are given the co ordinates of A, B and C, you have to find the coordinates of D and the area of the parallelogram. The orientation of ABCDshould be same as in the picture.
Each case starts with a line containing six integers Ax, Ay, Bx, By, Cx, Cy where (Ax, Ay) denotes the coordinate of A, (Bx,
By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range [-1000, 1000]. And you can assume
that A, B andC will not be collinear.
题意:
求平行四边形的D点和面积!
代码如下:
A parallelogram is a quadrilateral with two pairs of parallel sides. See the picture below:
Fig: a parallelogram
Now you are given the co ordinates of A, B and C, you have to find the coordinates of D and the area of the parallelogram. The orientation of ABCDshould be same as in the picture.
Input
Input starts with an integer T (≤ 1000), denoting the number of test cases.Each case starts with a line containing six integers Ax, Ay, Bx, By, Cx, Cy where (Ax, Ay) denotes the coordinate of A, (Bx,
By) denotes the coordinate of B and (Cx, Cy) denotes the coordinate of C. Value of any coordinate lies in the range [-1000, 1000]. And you can assume
that A, B andC will not be collinear.
Output
For each case, print the case number and three integers where the first two should be the coordinate of D and the third one should be the area of the parallelogram.Sample Input | Output for Sample Input |
3 0 0 10 0 10 10 0 0 10 0 10 -20 -12 -10 21 21 1 40 | Case 1: 0 10 100 Case 2: 0 -20 200 Case 3: -32 9 1247 |
求平行四边形的D点和面积!
代码如下:
#include <cstdio> #include <cmath> #include <cstring> #include <iostream> #include <algorithm> using namespace std; double dis(int x1, int y1, int x2, int y2) { return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)); } int main() { int t; int cas = 0; scanf("%d",&t); while(t--) { int ax,ay, bx, by, cx, cy; int dx, dy; double area; scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy); int xx = bx - ax; int yy = cy - by; dx = cx - xx; dy = ay + yy; double dis_AD = dis(ax,ay,dx,dy); double dis_DB = dis(dx,dy,bx,by); double dis_AB = dis(ax,ay,bx,by); double cosA; if(((dis_AD)*(dis_AD)+(dis_AB)*(dis_AB) == (dis_DB)*(dis_DB))) { cosA = 0; } else cosA = (dis_AD*dis_AD+dis_AB*dis_AB-dis_DB*dis_DB)/(2*dis_AD*dis_AB); double sinA = sqrt(1-cosA*cosA); area = dis_AD * dis_AB * sinA; printf("Case %d: %d %d %.0lf\n",++cas,dx,dy,area); } return 0; } /* 3 0 0 10 0 10 10 0 0 10 0 10 -20 -12 -10 21 21 1 40 */
相关文章推荐
- LightOJ - 1305 Area of a Parallelogram (数学几何)水
- lightoj 1305 Area of a Parallelogram (几何数学)
- lightoj-1305 - Area of a Parallelogram【数学】【向量法求平行四边形面积】
- Light OJ:1305 Area of a Parallelogram(水题+数学)
- LightOJ 1305-Area of a Parallelogram【几何】
- LightOJ 1305 Area of a Parallelogram
- 【LightOJ】1305 - Area of a Parallelogram(求平行四边形面积)
- LOJ 1305 - Area of a Parallelogram(数学j几何)
- lightoj-1305 - Area of a Parallelogram(几何)
- LightOJ 1305 Area of a Parallelogram
- light oj 1305 - Area of a Parallelogram (数学 平行四边形坐标和面积)
- LightOJ 1305 Area of a Parallelogram - Basic Geometry
- S - Area of a Parallelogram(数学)
- 【lightoj1305】 Area of a Parallelogram
- LIGHT OJ-1305 - Area of a Parallelogram 【向量叉积】
- 【light-oj】-1305 - Area of a Parallelogram(水)
- Light 1305 - Area of a Parallelogram【向量求解】
- 【lightoj1305】 Area of a Parallelogram
- lightoj 1045 - Digits of Factorial (数学-log运用--阶乘进制位数)
- lightOJ 1278 Sum of Consecutive Integers(数论,数学推导)