码迷,mamicode.com
首页 > 其他好文 > 详细

ZOJ2540 Form a Square

时间:2018-02-28 01:18:16      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:mes   ==   mat   ++   turn   组成   open   orm   std   

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

标签:mes   ==   mat   ++   turn   组成   open   orm   std   

原文地址:https://www.cnblogs.com/shirley-0021/p/8481608.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!