您的位置:首页 > 其它

NYOJ 1099 Lan Xiang's Square (判断是否为正四边形)

2015-11-27 18:50 253 查看

Lan Xiang's Square

时间限制:1000 ms  |  内存限制:65535 KB

难度:0
描述
       Excavator technology which is strong, fast to Shandong to find Lan Xiang.
       Then the question comes.. :)

       for this problem , i will give you four points. you just judge if they can form a square.

       if they can, print "Yes", else print "No".

       Easy ?  just AC it.

输入T <= 105 cases.

for every case

four points, and every point is a grid point .-10^8 <= all interger <= 10^8。

grid point is both x and y are interger.输出Yes or No样例输入
1
1 1
-1 1
-1 -1
1 -1

样例输出
Yes

提示
you think this is a easy problem ? you dare submit, i promise you get a WA. :)



大意:给出四个点,判断围成的图形是否为正四边形

思路:直接判断是否最短边存在4条,最长边存在两条就行了,可以自己手绘一下

ac代码:

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define MAXN 201000
#define MAX(a,b) a>b?a:b
#define fab(a) ((a)>0?(a):-(a))
#define mem(x) memset(x,0,sizeof(x))
#define INF 0xfffffff
using namespace std;
struct s
{
double x,y;
}a[5];
double dis[MAXN];
double fun(s aa,s bb)
{
return sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y));
}
int main()
{
int t,i,j;
scanf("%d",&t);
while(t--)
{
for(i=1;i<=4;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
double M=-1.0,mi=INF*1.0;
int k=0;
for(i=1;i<=4;i++)
{
for(j=i+1;j<=4;j++)
{
dis[k]=fun(a[i],a[j]);
M=max(dis[k],M);
mi=min(dis[k],mi);
k++;
}
}
int b=0,c=0;
for(i=0;i<k;i++)
{
if(dis[i]==M)
b++;
else if(dis[i]==mi)
c++;
}
if(b==2&&c==4)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: