思路:把所有的x坐标值加起来,并除以点的数目得到对称轴,再测试每个点是否有相对称的点。
用set < pair < int,int> >存储点
#include<iostream>
#include <functional>
#include<set>
using namespace std;
typedef pair<int, int> point;
int main()
{
set<point>P;
int n,x,y,sum = 0,sy;
cout << "有几个点:";
cin >> n;
cout << "输入各个点(q结束)";
while (cin >> x >> y)
{
sum += x;
P.insert(make_pair(x, y));
}
sy = sum / P.size();
bool IF = true;
for (auto it = P.begin(); it != P.end(); it++)
{
point po = *it;
if (P.find(point(sy * 2 - po.first, po.second)) == P.end())
{
IF = false;
break;
}
}
if (IF == true)
cout << "有!\n";
else
cout << "没有!\n";
return 0;
}