Pagini recente » Cod sursa (job #2628066) | Diferente pentru arbori-de-intervale intre reviziile 35 si 49 | Cod sursa (job #434953) | Cod sursa (job #1295427) | Cod sursa (job #1512293)
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#define DIM 805
#define infile "overlap.in"
#define outfile "overlap.out"
class Point {
public:
int x, y;
Point() {};
Point(int x, int y) {
this->x = x;
this->y = y;
}
void rotate(int rotation) {
if (rotation == 0)
return;
int x = -this->y, y = this->x;
this->x = x, this->y = y;
rotate(rotation - 1);
}
void shift(int shiftX, int shiftY) {
this->x += shiftX;
this->y += shiftY;
}
};
class Comp{
public:
bool operator()(const Point &a, const Point &b) {
return (a.x == b.x ? a.y > b.y : a.x > b.x);
}
};
Point points[DIM];
int pointCount;
std::map<Point, int, Comp> map;
int goTo[DIM], inDegree[DIM], solution[DIM];
bool vis[DIM];
int getLen(int pointIndex, int label) {
if (pointIndex == 0 || vis[pointIndex]) {
return 0;
}
vis[pointIndex] = true;
solution[pointIndex] = label;
return 1 + getLen(goTo[pointIndex], label ^ 1);
}
int main() {
std::ifstream fin(infile);
std::ofstream fout(outfile);
fin >> pointCount;
for (int index = 1; index <= pointCount; ++index) {
fin >> points[index].x >> points[index].y;
map[points[index]] = index;
}
for (int rotation = 0; rotation <= 3; ++rotation) {
for (int index = 2; index <= pointCount; ++index) {
Point point = points[index];
point.rotate(rotation);
int shiftX = points[1].x - point.x, shiftY = points[1].y - point.y;
memset(goTo, 0, sizeof goTo);
memset(inDegree, 0, sizeof inDegree);
for (int index2 = 1; index2 <= pointCount; ++index2) {
Point point = points[index2];
point.rotate(rotation);
point.shift(shiftX, shiftY);
if (map.find(point) == map.end())
continue;
goTo[index2] = map[point];
inDegree[map[point]]++;
}
memset(vis, 0, sizeof vis);
memset(solution, 0, sizeof solution);
bool ok = true;
for (int index2 = 1; index2 <= pointCount; ++index2) {
if (inDegree[index2] == 0 && getLen(index2, 1) % 2 == 1) {
ok = false;
break;
}
}
if (!ok)
continue;
for (int index2 = 1; index2 <= pointCount; ++index2) {
if (vis[index2] == false && getLen(index2, 1) % 2 == 1) {
ok = false;
break;
}
}
if (!ok)
continue;
for (int index2 = 1; index2 <= pointCount; ++index2) {
fout << solution[index2] + 1 << '\n';
}
return 0;
}
}
return 0;
}
//Trust me, I'm the Doctor!