From f764b3fb7db4265534d051be665b63be2b3e14cb Mon Sep 17 00:00:00 2001 From: Manuel Bucher <manuel.bucher@hu-berlin.de> Date: Sun, 24 Jun 2018 12:59:46 +0200 Subject: [PATCH] Passed check, with rearranged neighbours --- loesung.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/loesung.c b/loesung.c index 5b37b0b..fb46a70 100755 --- a/loesung.c +++ b/loesung.c @@ -185,14 +185,14 @@ int field_neighbours(Field *this) { return 1; // Doppelung } else if (t[cur].y-1 == t[east].y) { t[cur].neigh[1] = east; - t[east].neigh[3] = cur; + t[east].neigh[2] = cur; } } else { top = begin_line; begin_line = cur; // neue Zeile } // ermitteln der Zeilen-Beziehung - if (t[begin_line].x != 0 && t[top].x < t[begin_line].x - 1) { + if (begin_line != 1 && t[top].x < t[begin_line].x - 1) { // Zeilensprung => Warten bis zur naechsten Zeile angekommen } else if (t[top].x == t[cur].x - 1) { // finden, ob paar nach oben existiert O(n) fuer alle Nachbarn nach oben/unten. @@ -201,7 +201,7 @@ int field_neighbours(Field *this) { // aktuelle obere Kachel koennte benachbart sein if (t[top].y == t[cur].y) { // nicht auf naechste Zeile uebergegangen // Neue Verbindung oben/unten gefunden - t[top].neigh[2] = cur; + t[top].neigh[3] = cur; t[cur].neigh[0] = top; } } @@ -264,7 +264,7 @@ bool hk_bfs(Field *this) { Queue q; // Schlange von Kacheln queue_init(&q); Tile *t = this->tiles; - for (int i = 1; i < this->num_tiles; i++) { + for (uint32_t i = 1; i < this->num_tiles; i++) { // nur gerade Kacheln werden zur queue hinzufuegen if (tile_odd(&t[i])) { continue; @@ -318,15 +318,16 @@ bool hk_dfs(Field *this, uint32_t e) { void hk_print(Field *this) { Tile *t = this->tiles; - for (uint32_t i = 1; i < this->num_tiles; i++) { - //printf("%u\n", i); + /*for (uint32_t i = 1; i < this->num_tiles; i++) { + uint32_t p = t[i].pair; + printf("%u: %u %u;%u %u\n", i, t[i].x, t[i].y, t[p].x, t[p].y); if (this->tiles[i].pair == 0) { printf("None\n"); return; } - } + }*/ for (uint32_t i = 1; i < this->num_tiles; i++) { - if (tile_odd(&t[i])) + if (!tile_odd(&t[i])) continue; uint32_t p = t[i].pair; printf("%u %u;%u %u\n", t[i].x, t[i].y, t[p].x, t[p].y); @@ -360,8 +361,12 @@ int main() { fprintf(stderr, "Error: Duplicated entry\n"); // Duplikat exisitert break; } + //field_print(&f); + if (f.num_tiles - f.num_odd == f.num_odd) { printf("None\n"); + fprintf(stderr, "Ungleiche Knotenbelegung"); + break; } hk(&f); // Algorithmus von Hopcroft und Karp result = EXIT_SUCCESS; -- GitLab