#include <iostream> #include <vector> #include "message.h" #include "krazki.h" using namespace std; int main() { int h = PipeHeight(); int n = NumberOfDiscs(); long long w; vector<int> dc; for (long long i=1+MyNodeId()*n/NumberOfNodes();i<=MyNodeId()==NumberOfNodes()-1?n:(n/NumberOfNodes()+MyNodeId()*n/NumberOfNodes());i++) { for (long long j=1;j<=h;j++) { if (DiscDiameter(i)>HoleDiameter(j) || j==h) { w=j+1; break; } } if (MyNodeId()>0) { PutLL(0,w); } else dc.push_back(w); } if (MyNodeId()>0) Send(0); else { int H=0, temp; for (int i=0;i<dc.size();i++) { if (H<dc[i]) H=dc[i]; else H++; } for (int i=1;i<NumberOfNodes();i++) { Receive(i); for (int j=0;j<n/NumberOfNodes()+(MyNodeId()==NumberOfNodes()-1?n%NumberOfNodes():0);j++) { temp=GetLL(i); if (H<temp) H=temp; else H++; } } cout << H; } 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 | #include <iostream> #include <vector> #include "message.h" #include "krazki.h" using namespace std; int main() { int h = PipeHeight(); int n = NumberOfDiscs(); long long w; vector<int> dc; for (long long i=1+MyNodeId()*n/NumberOfNodes();i<=MyNodeId()==NumberOfNodes()-1?n:(n/NumberOfNodes()+MyNodeId()*n/NumberOfNodes());i++) { for (long long j=1;j<=h;j++) { if (DiscDiameter(i)>HoleDiameter(j) || j==h) { w=j+1; break; } } if (MyNodeId()>0) { PutLL(0,w); } else dc.push_back(w); } if (MyNodeId()>0) Send(0); else { int H=0, temp; for (int i=0;i<dc.size();i++) { if (H<dc[i]) H=dc[i]; else H++; } for (int i=1;i<NumberOfNodes();i++) { Receive(i); for (int j=0;j<n/NumberOfNodes()+(MyNodeId()==NumberOfNodes()-1?n%NumberOfNodes():0);j++) { temp=GetLL(i); if (H<temp) H=temp; else H++; } } cout << H; } return 0; } |