#include "kollib.h" #include "message.h" #include <stdio.h> using namespace std; int main() { int ktoryJestemWezel = MyNodeId(); if(ktoryJestemWezel == 0){ int iloscStudentow = NumberOfStudents(); int iloscZapytan = NumberOfQueries(); int* odleglosci = new int[iloscStudentow+1]; int currentID = 1; int cameFrom = FirstNeighbor(currentID); odleglosci[1] = 0; for (int odleglosc=1; odleglosc<iloscStudentow; odleglosc++){ if(FirstNeighbor(currentID) == cameFrom){ cameFrom = currentID; currentID = SecondNeighbor(currentID); } else{ cameFrom = currentID; currentID = FirstNeighbor(currentID); } odleglosci[currentID] = odleglosc; } int halfStudents = iloscStudentow/2; for(int zapytanie = 1; zapytanie <= iloscZapytan; zapytanie ++){ int firstPerson = QueryFrom(zapytanie); int secondPerson = QueryTo(zapytanie); int delta = (iloscStudentow + odleglosci[firstPerson] - odleglosci[secondPerson])%iloscStudentow; if(delta>halfStudents) delta = iloscStudentow-delta; printf("%d\n",delta); } } return 0; };
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include "kollib.h" #include "message.h" #include <stdio.h> using namespace std; int main() { int ktoryJestemWezel = MyNodeId(); if(ktoryJestemWezel == 0){ int iloscStudentow = NumberOfStudents(); int iloscZapytan = NumberOfQueries(); int* odleglosci = new int[iloscStudentow+1]; int currentID = 1; int cameFrom = FirstNeighbor(currentID); odleglosci[1] = 0; for (int odleglosc=1; odleglosc<iloscStudentow; odleglosc++){ if(FirstNeighbor(currentID) == cameFrom){ cameFrom = currentID; currentID = SecondNeighbor(currentID); } else{ cameFrom = currentID; currentID = FirstNeighbor(currentID); } odleglosci[currentID] = odleglosc; } int halfStudents = iloscStudentow/2; for(int zapytanie = 1; zapytanie <= iloscZapytan; zapytanie ++){ int firstPerson = QueryFrom(zapytanie); int secondPerson = QueryTo(zapytanie); int delta = (iloscStudentow + odleglosci[firstPerson] - odleglosci[secondPerson])%iloscStudentow; if(delta>halfStudents) delta = iloscStudentow-delta; printf("%d\n",delta); } } return 0; }; |