第四届程序设计大赛 垂直

第四届程序设计大赛 垂直

Time Limit:1000MS  Memory Limit:65536K
Total Submit:516 Accepted:207

Description

在一个二维坐标平面给定4个顶点,判定是否存在两条互相垂直的线。

Input

每行输入数据均包含一个顶点的坐标X和Y,以空格分开。-100 <= X,Y <= 100。

Output

输出YES或者NO

Sample Input

0 0
1 0
0 -1
0 1

Sample Output

YES

  • Source

#include<stdio.h>
int main()
{
	int i1,i2,j1,j2,t=1;
	double x[5],y[5],k1,k2;
	for(i1=0;i1<4;i1++)
	{
		scanf("%lf%lf",&x[i1],&y[i1]);
	}
	for(i1=0;i1<4;i1++)
	{
		for(j1=0;j1<4;j1++)
		{
			k1=(y[i1]-y[j1])/(x[i1]-y[j1]);
			for(i2=0;i2<4;i2++)
			{
				for(j2=0;j2<4;j2++)
				{
					k2=(y[i2]-y[j2])/(x[i2]-x[j2]);
					if(k1*k2==-1)
					{
						printf("YES");
						t=0;
						goto end;
					}
				}
			}
		}
	 } 
	 end:
	 	if(t)
	 	{
	 		printf("NO");
		 }
		 return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40789841/article/details/80967173