ZOJ2540 Form a Square

Posted shirley-wang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ZOJ2540 Form a Square相关的知识,希望对你有一定的参考价值。

Form a Square

题意就是 判断 给你四个点,能否组成一个正方形

要点:

格式很重要, 很重要!!!

数据很小,直接暴力

四个点判断是否为正方形,只需将所有可能的边长度算出来,然后选其中最短的边作为正方形的边长,进行比较,看有没有符合的四条边

 

技术分享图片
 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cmath>
 4 using namespace std;
 5 const int N = 4;
 6 typedef struct aa{
 7     int x, y;
 8 }AA;
 9 AA a[N];
10 
11 double dis(AA b, AA c)
12 {
13     double len = sqrt((b.x - c.x) * (b.x - c.x) + (b.y - c.y) * (b.y - c.y));
14     return len;
15 }
16 int main()
17 {
18     int t, num, cnt = 1;
19     cin >> t;
20     int T = t;
21     while(T--)
22     {
23         for(int i = 0; i < 4; i++)
24         {
25             cin >> a[i].x >> a[i].y;
26         } 
27         double ll = 2010;
28         num = 0;
29         for(int i = 0; i < 4; i++)
30         {
31             for(int j = i+1; j < 4; j++)
32             {
33                 double dist = dis(a[i], a[j]);
34                 if(dist == ll)
35                 {
36                     num++;
37                 }
38                 else if(dist < ll)
39                 {
40                     ll = dist;
41                     num = 1;
42                 }
43             }
44         }
45         if(num == 4)
46         {
47             if(cnt != t)
48                 cout << "Case " << "" << cnt++ << ":" << endl << "Yes" << endl << endl;
49             else
50                 cout << "Case " << "" << cnt++ << ":" << endl << "Yes";
51         }
52         else
53         {
54             if(cnt != t)
55                 cout << "Case " << "" << cnt++ << ":" << endl << "No" << endl << endl;
56             else
57                 cout << "Case " << "" << cnt++ << ":" << endl << "No";
58         }
59         
60     }
61     return 0;
62 }
View Code

 

以上是关于ZOJ2540 Form a Square的主要内容,如果未能解决你的问题,请参考以下文章

用蓝牙芯片CC2541/CC2540实现一个智能恒温箱

SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段

群赛 ZOJ3741(dp) ZOJ3911(线段树)

zoj3888

ZOJ 3844Easy Task

BLE蓝牙SOC CC2540之一:基本的了解