UESTC 1033 Marineking wilyin

来源:互联网 发布:淘宝csv数据怎么制作 编辑:程序博客网 时间:2024/06/11 06:35

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
20 0 1 0 0 10 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;}

谢谢

0 0
原创粉丝点击