zoukankan      html  css  js  c++  java
  • 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
    Just do what you want!
  • 相关阅读:
    [Swift]LeetCode900. RLE 迭代器 | RLE Iterator
    TNS-12508 When Issuing Any SET Command For The Listene
    shell getopts
    archive log full ora-00257
    php 验证码
    php 缩略图
    弧度
    php输出中文字符
    流程图
    windows clone 迁移数据库
  • 原文地址:https://www.cnblogs.com/shirley-0021/p/8481608.html
Copyright © 2011-2022 走看看