A - Marineking wilyin
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
Submit Status
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 |
#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]); } }
时间: 2024-12-29 07:05:11