码迷,mamicode.com
首页 > 其他好文 > 详细

Marineking wilyin

时间:2014-12-27 18:50:25      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:

A - 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 InputSample Output
2
0 0 1 0 0 1
0 1 0 -1 1 0
1 1
-1 0

 

#include <iostream>
#include <cstring>
#include <cstdio>

#include <queue>
#include <stack>
#include <cmath>
using namespace std;
int main()
{
#ifdef CDZSC_OFFLINE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

    int n;
    scanf("%d",&n);
    while (n--)
    {
        int a[3][2];
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<2;j++)
            {
                scanf("%d",&a[i][j]);
            }
        }
        for(int i=0;i<3;i++)
        {
            int x=(a[i][1]-a[(i+1)%3][1])*(a[i][1]-a[(i+1)%3][1])+(a[i][0]-a[(i+1)%3][0])*(a[i][0]-a[(i+1)%3][0]);
            int y=(a[i][1]-a[(i+2)%3][1])*(a[i][1]-a[(i+2)%3][1])+(a[i][0]-a[(i+2)%3][0])*(a[i][0]-a[(i+2)%3][0]);
            int z=(a[(i+1)%3][1]-a[(i+2)%3][1])*(a[(i+1)%3][1]-a[(i+2)%3][1])+(a[(i+1)%3][0]-a[(i+2)%3][0])*(a[(i+1)%3][0]-a[(i+2)%3][0]);
            if(x+y==z)//寻找直角点
            {
                swap(a[i][0],a[2][0]);
                swap(a[i][1],a[2][1]);
                break;

            }
        }
        printf("%d ",a[1][0]+a[0][0]-a[2][0]);
        printf("%d\n",a[1][1]+a[0][1]-a[2][1]);
    }
}

 

 

Marineking wilyin

标签:

原文地址:http://www.cnblogs.com/guofeng1022/p/4188702.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!