还是暴力
只需要判断是否关于竖直线堆成
写两个数组
一个按照先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; }
这题是受数据结构里栈和队列课后作业的启发
然后顺便复习了一下结构体运算符重载