BOJ 1562 Rectangle

Rectangle
Accept:11    Submit:14
Time Limit:1000MS    Memory Limit:65536KB

Rectangle

 

Description

 

Given three vertices of a rectangle on a 2D plane, you're required to determine the coordinate of the fourth vertex.

 

Input Format

 

An integer T(T100) 
will exist in the first line of input, indicating the number of test cases.

Each test case consists of three lines, each with a pair of integers (x,y) 
, which denotes a coordinate of a vertex.

All the coordinates will be set in range [10000,10000] 
. Note that the given vertices will exactly form a right angle.

 

Output Format

 

For each test case, output the coordinate of the required vertex.

 

Sample Input

 
2
0 0
0 2
3 0
-1 1
0 0
1 1
 

Sample Output

 
3 2
0 2

给一个矩形的三个顶点,求第四个
我的做法是先用向量乘积为0的方法判断出给出的三点中的直角顶点,再由直角顶点和对角线中点确定出第四个顶点

 1 #include<iostream>
 2 
 3 using namespace std;
 4 
 5 typedef struct point
 6 {
 7     long x;
 8     long y;
 9 } POINT;
10 
11 typedef struct vector
12 {
13     long x;
14     long y;
15 } VECTOR;
16 
17 POINT f(POINT l,POINT r,POINT m)
18 {
19     POINT mid,result;
20     mid.x=l.x+r.x;
21     mid.y=l.y+r.y;
22     result.x=mid.x-m.x;
23     result.y=mid.y-m.y;
24     return result;
25 }
26 
27 int main()
28 {
29     int t;
30     POINT a,b,c,d;
31     VECTOR m,n,p;
32 
33     cin>>t;
34 
35     while(t--)
36     {
37         cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y;
38         m.x=a.x-b.x;
39         m.y=a.y-b.y;
40         n.x=b.x-c.x;
41         n.y=b.y-c.y;
42         p.x=c.x-a.x;
43         p.y=c.y-a.y;
44         if(m.x*n.x+m.y*n.y==0)
45             d=f(a,c,b);
46         else if(n.x*p.x+n.y*p.y==0)
47             d=f(a,b,c);
48         else if(p.x*m.x+p.y*m.y==0)
49             d=f(b,c,a);
50         cout<<d.x<<" "<<d.y<<endl;
51     }
52 
53     return 0;
54 }
[C++]

 

转载于:https://www.cnblogs.com/lzj-0218/p/3181351.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值