zoukankan      html  css  js  c++  java
  • 算法习题---5-6对称轴(UVa1595)

    一:题目

    判断平面上的一组点,是否关于一条竖线对称。即找到一条垂直对称轴

    (一)样例输入

    3
    5
    -2 5
    0 0
    6 5
    4 0
    2 3
    4
    2 3
    0 4
    4 0
    0 0
    4
    5 14
    6 10
    5 10
    6 14

    (二)样例输出

    YES
    NO
    YES

    二:代码实现

    #define _CRT_SECURE_NO_WARNINGS
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    #define MAX_LEN 1000
    
    typedef struct Pot
    {
        double x;
        double y;
        bool operator<(struct Pot& other)const
        {
            return x < other.x;
        }
    }Pots;
    
    int main()
    {
        freopen("data5_6_h.in", "r", stdin);
        freopen("data5_6_h.out", "w", stdout);
    
        Pots pos[MAX_LEN];
        double check_pos;
    
        int total_num, num,i;
        cin >> total_num;
        while (total_num--)
        {
            cin >> num;        //信息获取
            for (i = 0; i < num; i++)
                cin >> pos[i].x >> pos[i].y;
    
            sort(pos, pos + num);  //排序后我们只需要找到中心点(最靠近中间的那两个,或者那一个点)即可check_pos
            if (num % 2 == 0)
                check_pos = (pos[num / 2 - 1].x + pos[num / 2].x) / 2;
            else
                check_pos = pos[num / 2].x;
            
            bool flag=true;
            for (int i = 0; i < num / 2; i++)        //进行信息校验
                if (pos[i].y != pos[num-i-1].y || (pos[i].x + pos[num-i-1].x) / 2 != check_pos)
                {
                    flag = false;
                    break;
                }
            if (flag)
                cout << "YES" << endl;
            else
                cout << "NO" << endl;
        }
    
        freopen("CON", "r", stdin);
        freopen("CON", "w", stdout);
        return 0;
    }
  • 相关阅读:
    yii源码五
    yii源码四
    yii源码三 -- db
    yii源码二 -- interfaces
    yii源码一 -- CComponent
    jquery效果 窗口弹出案例
    JS滚动条
    JS表单验证
    [TCP/IP] TCP流和UDP数据报之间的区别
    [TCP/IP] 关闭连接后为什么客户端最后还要等待2MSL
  • 原文地址:https://www.cnblogs.com/ssyfj/p/11547773.html
Copyright © 2011-2022 走看看