#include <iostream> #include "kollib.h" #include "message.h" using namespace std; int ind1, ind2, pre1, pre2, cel, odl; int main() { ios_base::sync_with_stdio(0); if(MyNodeId()>0) // Licz { for(int i=MyNodeId(); i<=NumberOfQueries(); i+=NumberOfNodes()) { pre1 = pre2 = -1; ind1 = ind2 = QueryFrom(i); cel = QueryTo(i); odl = 0; if(ind1!=cel) { while(odl<=NumberOfStudents()/2) { if(ind1 == cel || ind2 == cel) { break; } if(FirstNeighbor(ind1)!=pre1) { pre1 = ind1; ind1 = FirstNeighbor(ind1); } else { pre1 = ind1; ind1 = SecondNeighbor(ind1); } if(FirstNeighbor(ind2)!=pre2) { pre2 = ind2; ind2 = FirstNeighbor(ind2); } else { pre2 = ind2; ind2 = SecondNeighbor(ind2); } ++odl; } } PutInt(0, odl); Send(0); } } if(MyNodeId()==0) // Wyswietl { for(int i=0; i<NumberOfQueries(); ++i) { Receive((i%NumberOfNodes())+1); cout << GetInt((i%NumberOfNodes())+1) << endl; } } 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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | #include <iostream> #include "kollib.h" #include "message.h" using namespace std; int ind1, ind2, pre1, pre2, cel, odl; int main() { ios_base::sync_with_stdio(0); if(MyNodeId()>0) // Licz { for(int i=MyNodeId(); i<=NumberOfQueries(); i+=NumberOfNodes()) { pre1 = pre2 = -1; ind1 = ind2 = QueryFrom(i); cel = QueryTo(i); odl = 0; if(ind1!=cel) { while(odl<=NumberOfStudents()/2) { if(ind1 == cel || ind2 == cel) { break; } if(FirstNeighbor(ind1)!=pre1) { pre1 = ind1; ind1 = FirstNeighbor(ind1); } else { pre1 = ind1; ind1 = SecondNeighbor(ind1); } if(FirstNeighbor(ind2)!=pre2) { pre2 = ind2; ind2 = FirstNeighbor(ind2); } else { pre2 = ind2; ind2 = SecondNeighbor(ind2); } ++odl; } } PutInt(0, odl); Send(0); } } if(MyNodeId()==0) // Wyswietl { for(int i=0; i<NumberOfQueries(); ++i) { Receive((i%NumberOfNodes())+1); cout << GetInt((i%NumberOfNodes())+1) << endl; } } return 0; } |