hrbust 2275 Square【水题】

Square
Time Limit: 1000 MSMemory Limit: 32768 K
Total Submit: 60(18 users)Total Accepted: 20(18 users)Rating: Special Judge: No
Description
You are given four points, determine whether they can form a square in a two-dimensional plane. Note the area of the square must be positive.
Input
There are multiple test cases.
Each test case is a single line containing 8 integers x1 y1 x2 y2 x3 y3 x4 y4, which are the coordinates of the four points. All integers in the input are in the range of [−109 , 109 ].
Output
For each test case, output a single line containing “YES” or “NO”.
Sample Input
0 0 0 1 1 1 1 0
Sample Output
YES
Source
“尚学堂杯”2015级程序设计竞赛(11月)正式赛

给你八个点,判断它能否在直角坐标系中构建成一个正方形,如果可以,输出YES,否则输出NO.

思路:求出正方形中的六条边(四个边,两个对角线)的长度,然后对其排序,前四个边长相同并且后两个相同,并且前边边长的平方*2==后边边长的平方。

注意的点:

1、数据比较大,当有平方加和之类的操作的时候是一定会超int的。

2、注意重点现象。

AC代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define ll long long int
struct zuobiao
{
    ll x,y;
}p[5];
int main()
{
    while(~scanf("%lld%lld%lld%lld%lld%lld%lld%lld",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y,&p[3].x,&p[3].y))
    {
        ll  juli[6];
        int cont=0;
        for(int i=0;i<4;i++)
        {
            for(int j=0;j<i;j++)
            {
                juli[cont]=(p[i].x-p[j].x)*(p[i].x-p[j].x)+(p[i].y-p[j].y)*(p[i].y-p[j].y);
                cont++;
            }
        }
        sort(juli,juli+cont);
        if(juli[0]==juli[1]&&juli[1]==juli[2]&&juli[2]==juli[3]&&juli[4]==juli[5]&&juli[0]*2==juli[4]&&juli[0]!=0)
        {
            printf("YES\n");
        }
        else printf("NO\n");
    }
}





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值