TOJ 2772.Parallelogram

题目链接:http://acm.tju.edu.cn/toj/showp2772.html


2772.    Parallelogram
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.

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

  • All the coordinates are between -1000 and 1000.
  • 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
    Submit   List    Runs   Forum   Statistics

    水题,过之:

    #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");
    	}
    }


    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值