这题不难,但细节比较多,排序的依据有很多,比较容易出错。考差C++和STL也比较全面,比如结构体、构造函数、map、pair、vector、sort、unique、copy等等,使用C++11的lambda配合泛型算法是一个很好的选择。
#include <bits/stdc++.h>
#define EPS 1e-7
using namespace std;
struct MAP
{
string name;
double x1, y1, x2, y2, area, Ratio;
pair<double, double> center;
int ilevel = -1;
MAP(double _x1, double _y1, double _x2, double _y2, string _name) :
x1(_x1), y1(_y1), x2(_x2), y2(_y2), name(_name) {
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
area = (x2 - x1) * (y2 - y1);
center.first = (x1 + x2) / 2.0;
center.second = (y1 + y2) / 2.0;
Ratio = (y2 - y1) / (x2 - x1);
}
bool contain(pair<double, double> x) const {
return x.first >= x1 && x.first <