UESTC 1033 Marineking wilyin

117 篇文章 2 订阅
53 篇文章 0 订阅

Marineking wilyin

Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others)
 

There are three marines in wilyin's base. Their positions form a right triangle.Now wilyin get another marine,he want to put it on some place to 

form a rectangle with the former three marines.where should he put it on?

Input

The first line of the input contains an integer  T  which means the number of test cases. Then  T  lines follow, each line consists of  6  positive 

integers  x1,y1,x2,y2,x3,y3  which means the positions of these three marines.

You may assume the absolute value of coordinate not exceed  3000 .

Output

For each case, print the coordinate of the forth marine on a single line.

Sample input and output

Sample Input Sample Output
2
0 0 1 0 0 1
0 1 0 -1 1 0
1 1
-1 0

My Solution

推导一下数学公示,解决数学问题
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

//用到了白书数据结构-例题6-5中,我自己学到的小技巧。
void jiaohuan(int &x1,int &y1,int &x2,int &y2,int &x3,int &y3)
{
    int x12=x1-x2,y12=y1-y2,x13=x1-x3,y13=y1-y3,x23=x2-x3,y23=y2-y3;
    if((x12*x13+y12*y13)==0) return;
    else if((x12*x23+y12*y23)==0) {swap(x1,x2);swap(y1,y2);}
    else {swap(x1,x3);swap(y1,y3);}
}
int main()
{
    int T,x1,y1,x2,y2,x3,y3,x,y;//令x1,y1为直角的顶点
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);//cout<<x1<<y1<<x2<<y2;
        jiaohuan(x1,y1,x2,y2,x3,y3);
        x=x2+x3-x1;
        y=y2+y3-y1;
        if(T) printf("%d %d\n",x,y);
        else printf("%d %d",x,y);
    }
    return 0;
}

谢谢

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值