lightoj-1305 - Area of a Parallelogram(几何)

1305 - Area of a Parallelogram
PDF (English) Statistics Forum
Time Limit: 1 second(s) Memory Limit: 32 MB
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 ABCD should 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 and C 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

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){

    int T,ax,ay,bx,by,cx,cy,dx,dy;
    scanf("%d",&T);
    for(int t=1;t<=T;t++){
        scanf("%d%d%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy);
        dx = cx-bx+ax,dy = cy-by+ay;
        int area = abs((cy-by)*(ax-bx)-(ay-by)*(cx-bx));
        printf("Case %d: %d %d %d\n",t,dx,dy,area);
        // 下面这种写法时记得要对abs()进行类型转换,不然WA
        //printf("Case %d: %d %d %d\n",t,dx,dy,(int)abs((cy-by)*(ax-bx)-(ay-by)*(cx-bx)));
    }
}
时间: 2024-08-02 19:07:57

lightoj-1305 - Area of a Parallelogram(几何)的相关文章

LightOJ 1305 - Area of a Parallelogram(数学啊 )

题目链接: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 coordi

lightoj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

LightOJ Beginners Problems 部分题解

相关代码请戳 https://coding.net/u/tiny656/p/LightOJ/git 1006 Hex-a-bonacci. 用数组模拟记录结果,注意取模 1008 Fibsieve's Fantabulous Birthday. 找规律题,左边列是1 3平方 5平方......下边行是1 2平方 4平方......,找到当前数被包夹的位置,然后处理一下位置关系,注意奇偶. 1010 Kinghts in Chessboard. 规律题,对于m,n大于2的情况下,使用交叉放置的方法

light oj Beginners Problems

很多以前写的丑代码 1000 - Greetings from LightOJ #include<math.h> #include<stdio.h> #include<stdlib.h> #include<string.h> int main(void) { int a,b,n,Case; scanf("%d",&n); Case=0; while(Case++,n--) { scanf("%d%d",&

(转载)Cross product

原文地址:https://en.wikipedia.org/wiki/Cross_product Cross product From Wikipedia, the free encyclopedia This article is about the cross product of two vectors in three-dimensional Euclidean space. For other uses, see Cross product (disambiguation). In m

android省市区三级联动案例:(二)项目结构图

目录结构 城市数据address.xml文件 <?xml version="1.0" encoding="utf-8"?> <root name="中国"> <province name="北京市"> <city name="北京市" index="1"> <area name="东城区" index="

hdu---(Tell me the area)(几何/三角形面积以及圆面积的一些知识)

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1876    Accepted Submission(s): 567 Problem Description There are two circles in the plane (shown in the below picture), there is

LightOJ Aladdin and the Flying Carpet 1341【算数基本定理+几何】

1341 - Aladdin and the Flying Carpet PDF (English) Statistics Forum Time Limit: 3 second(s) Memory Limit: 32 MB It's said that Aladdin had to solve seven mysteries before getting the Magical Lamp which summons a powerful Genie. Here we are concerned

LightOJ - 1058 - Parallelogram Counting(数学,计算几何)

链接: https://vjudge.net/problem/LightOJ-1058 题意: There are n distinct points in the plane, given by their integer coordinates. Find the number of parallelograms whose vertices lie on these points. In other words, find the number of 4-element subsets o