#include "dzialka.h" #include "message.h" #include <iostream> int main() { const int H = GetFieldHeight(); const int W = GetFieldWidth(); long long configurations = 0; for (int x0 = MyNodeId()*W / NumberOfNodes(); x0 < (MyNodeId() + 1)*W / NumberOfNodes(); ++x0) { for (int y0 = MyNodeId()*H / NumberOfNodes(); y0 < (MyNodeId() + 1)*H / NumberOfNodes(); ++y0) { if (!IsUsableCell(y0, x0)) { continue; } ++configurations; int xBound = W; int y = y0; int x = x0 + 1; bool isSearchFinished = false; while (!isSearchFinished && y >= 0) { for (; x < xBound; ++x) { if (IsUsableCell(y, x)) { ++configurations; } else { xBound = x; if (xBound == x0) { isSearchFinished = true; } } } x = x0; --y; } } } if (MyNodeId() > 0) { PutLL(0, configurations); Send(0); } else { // MyNodeId == 0 for (int instance = 1; instance < NumberOfNodes(); ++instance) { Receive(instance); configurations += GetLL(instance); } std::cout << configurations << std::endl; } }
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 | #include "dzialka.h" #include "message.h" #include <iostream> int main() { const int H = GetFieldHeight(); const int W = GetFieldWidth(); long long configurations = 0; for (int x0 = MyNodeId()*W / NumberOfNodes(); x0 < (MyNodeId() + 1)*W / NumberOfNodes(); ++x0) { for (int y0 = MyNodeId()*H / NumberOfNodes(); y0 < (MyNodeId() + 1)*H / NumberOfNodes(); ++y0) { if (!IsUsableCell(y0, x0)) { continue; } ++configurations; int xBound = W; int y = y0; int x = x0 + 1; bool isSearchFinished = false; while (!isSearchFinished && y >= 0) { for (; x < xBound; ++x) { if (IsUsableCell(y, x)) { ++configurations; } else { xBound = x; if (xBound == x0) { isSearchFinished = true; } } } x = x0; --y; } } } if (MyNodeId() > 0) { PutLL(0, configurations); Send(0); } else { // MyNodeId == 0 for (int instance = 1; instance < NumberOfNodes(); ++instance) { Receive(instance); configurations += GetLL(instance); } std::cout << configurations << std::endl; } } |