zoukankan      html  css  js  c++  java
  • uva 1595 Symmetry 暴力

    还是暴力

    只需要判断是否关于竖直线堆成

    写两个数组

    一个按照先x升序后y降序排

    一个按照先x降序后y降序排

    然后从0扫到(n/2+1)就好

    判x之和是否相等和y坐标是否相等即可

    弱校连萌题目链接:http://acm.bnu.edu.cn/v3/contest_show.php?cid=5772#problem/N

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <set>
    #include <queue>
    #include <stack>
    #include <map>
    #include <vector>
    
    using namespace std;
    
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<int, int> P;
    
    const int maxn = 1100;
    
    struct P1
    {
        int x, y;
        bool operator < (const P1& a) const
        {
            return x < a.x || (x == a.x && y > a.y);
        }
    }p1[maxn];
    
    struct P2
    {
        int x, y;
        bool operator < (const P2& a) const
        {
            return x > a.x || (x == a.x && y > a.y);
        }
    }p2[maxn];
    
    
    int main()
    {
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    
        int T;
        scanf("%d", &T);
        while(T--)
        {
            int n;
            scanf("%d", &n);
    
            for(int i = 0; i < n; i++)
            {
                scanf("%d%d", &p1[i].x, &p1[i].y);
                p2[i].x = p1[i].x;
                p2[i].y = p1[i].y;
            }
    
            sort(p1, p1 + n);
            sort(p2, p2 + n);
    
            bool flag = true;
            int sum = p1[0].x + p2[0].x;
    
            for(int i = 0; i < n/2+1; i++)
            {
                if(p1[i].x + p2[i].x != sum || p1[i].y != p2[i].y)
                {
                    flag = false;
                    break;
                }
            }
    
            if(flag)
                printf("YES
    ");
            else
                printf("NO
    ");
    
    
        }
    
        return 0;
    }

    这题是受数据结构里栈和队列课后作业的启发

    然后顺便复习了一下结构体运算符重载

  • 相关阅读:
    IntelliJ如何设置自动导包
    203.数的表示
    202.磁悬浮动力系统应用研究与模型搭建
    201.一种六磁子交通系统
    200.软件工程_期末_李振宏老师
    199.维护
    SSH学习-Struts2中的session
    SSH学习-Struts2消息传递机制
    SSH学习-struts2配置基本步骤
    云笔记项目-MyBatis关联映射查询
  • 原文地址:https://www.cnblogs.com/dishu/p/4265267.html
Copyright © 2011-2022 走看看