ZOJ2540 Form a Square

Form a Square

題意就是 判斷 給你四個點,可否組成一個正方形ios

要點:ide

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

數據很小,直接暴力code

四個點判斷是否爲正方形,只需將全部可能的邊長度算出來,而後選其中最短的邊做爲正方形的邊長,進行比較,看有沒有符合的四條邊orm

 

 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
相關文章
相關標籤/搜索