题意:在笛卡尔坐标系上给定n个点的x,y坐标,判断是否左右对称
auto 遍历map,vector:
#include <iostream> #include <map> #include <queue> using namespace std; int main() { map<int, string> mp; mp.insert(pair<int,string>(2,"hello")); mp.insert(pair<int,string>(1,"miaomiaomiao")); mp.insert(pair<int,string>(3,"world")); for(auto &p : mp) cout << p.first << endl; return 0; }
int main() { vector <int> vec; //vec.push_back(); for(auto &p : vec)//这里这样可以实现从第一个元素开始遍历输出vec count << p << endl; /*等价于 for(int i = 0; i < vec.size(); ++i) { count << vec[i] << endl; } */ return 0; }
#include<bits/stdc++.h>int main(void) { int t=0,n=0,x,y; scanf("%d",&t); while(t--) { scanf("%d",&n); map<int,vector<int> > mp; for(int i=0;i<n;i++) { scanf("%d%d",&x,&y); mp[y].push_back(x); } set<int> mset; for(auto p: mp) { sort(p.second.begin(),p.second.end()); int timess=(p.second.size()+1)/2; for(int i=0;i<timess;i++) mset.insert(p.second[i]+p.second[p.second.size()-i-1]); } printf("%s ", mset.size() == 1 ? "YES" : "NO"); } return 0; }