题目链接:http://acm.tju.edu.cn/toj/showp2772.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 1113 Accepted Runs: 505
As a student of applied mathematics school of UESTC, WCM likes mathematics. Recently he is absorbed in geometry. But a very easy problem puzzled him. He can't know how to determine whether a quadrilateral is a parallelogram or not. How poor he is! He believes that you, who are regarded as one of his smartest friend, can solve this problem easily.
All the coordinates are between -1000 and 1000.
Given two segments, AC and BD, you should determine whether quadrilateral ABCD is a parallelogram whose diagonals are AC and BD.
Input
The first line contains a positive integer T, which means the number of test cases. For each test case, the first line contains four integers X 1,Y 1,X 3,Y 3, (X 1,Y 1) is the coordinates of A and (X 3,Y 3) is the coordinates of C. The second line consists of four integers X 2,Y 2,X 4,Y 4, (X 2,Y 2) is the coordinates of B and (X 4,Y 4) is the coordinates of D. You can assume that points A, B, C and D are different from each other.Output
For each test case, if quadrilateral ABCD is a parallelogram whose diagonals are AC and BD, then output Yes on a line; otherwise, output No.Constraints
Sample Input
2 -1 -1 3 3 -2 0 4 2 -1 -2 3 4 3 7 6 9
Sample Output
Yes No
Source: The 5th UESTC Programming Contest Warmup
水题,过之:
#include <stdio.h>
using namespace std;
int main(){
int ax,ay,cx,cy,bx,by,dx,dy,n;
scanf("%d",&n);
while(n--){
scanf("%d%d%d%d\n%d%d%d%d",&ax,&ay,&bx,&by,&cx,&cy,&dx,&dy);
int flag=0;
if((cx-ax)*(cx-ax)+(cy-ay)*(cy-ay)==(bx-dx)*(bx-dx)+(by-dy)*(by-dy)){
if(cx==ax||dx==bx){
if(cx==ax&&dx==bx)
flag=1;
}
else{
double k1=(1.0*(cy-ay))/(cx-ax);
double k2=(1.0*(dy-by))/(dx-bx);
if(k1==k2)
flag=1;
}
}
if(flag)
printf("Yes\n");
else
printf("No\n");
}
}