#include #include #include #include #include #include using namespace std; class ThreeTeleports { public: int shortestDistance(int xMe, int yMe, int xHome, int yHome, vector teleports); }; int ThreeTeleports::shortestDistance(int xMe, int yMe, int xHome, int yHome, vector teleports) { vector X, Y; vector < vector >AM; int i, j, x1, x2, y1, y2; long long xd, yd; /* Create the vectors X and Y, which hold the x and y coordinates of the eight locations that we care about. */ X.push_back(xMe); Y.push_back(yMe); for (i = 0; i < teleports.size(); i++) { sscanf(teleports[i].c_str(), "%d %d %d %d", &x1, &y1, &x2, &y2); X.push_back(x1); Y.push_back(y1); X.push_back(x2); Y.push_back(y2); } X.push_back(xHome); Y.push_back(yHome); /* Create the adjacency matrix. */ AM.resize(X.size()); for (i = 0; i < X.size(); i++) { for (j = 0; j < X.size(); j++) { xd = X[j]-X[i]; if (xd < 0) xd = -xd; yd = Y[j]-Y[i]; if (yd < 0) yd = -yd; AM[i].push_back(xd+yd); } } /* Print the adjacency matrix. */ for (i = 0; i < AM.size(); i++) { for (j = 0; j < AM[i].size(); j++) { printf("%6lld", AM[i][j]); } printf("\n"); } return 0; }