#include "message.h" #include "krazki.h" #include<algorithm> #include<cstdio> const long long inf = 1000000000000000001; const long long int range = 4000000; long long minis[4000010]; int main() { int me = MyNodeId(); int node_num = NumberOfNodes(); long long int pocz = 1, minimum = inf; long long int koniec = PipeHeight(); if(me > 0) { Receive(me - 1); pocz = GetLL(me - 1); minimum = GetLL(me - 1); } for(int i = 0; i < (int)(std::min(range, koniec - pocz + 1)); i++) { minimum = std::min(minimum, HoleDiameter(((long long)i) + pocz)); minis[i] = minimum; //printf("%lld %lld\n", minis[i], minimum); } long long int j = 1; if(me < node_num - 1) { PutLL(me + 1, pocz + std::min(range, koniec - pocz + 1)); PutLL(me + 1, minimum); Send(me + 1); Receive(me + 1); j = GetLL(me + 1); } if(pocz < koniec && j <= NumberOfDiscs()) { long long disc_size = DiscDiameter(j); for(int i = (int)(std::min(range, koniec - pocz + 1)) - 1; i >= 0; i--) { //printf("%d %lld %lld\n", i, j, disc_size); if(minis[i] >= disc_size) { j++; if(j <= NumberOfDiscs()) disc_size = DiscDiameter(j); else { printf("%lld\n", ((long long)i) + pocz); break; } } } } if(me > 0) { PutLL(me - 1, j); Send(me - 1); } else { if(j <= NumberOfDiscs()) printf("0\n"); } 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 | #include "message.h" #include "krazki.h" #include<algorithm> #include<cstdio> const long long inf = 1000000000000000001; const long long int range = 4000000; long long minis[4000010]; int main() { int me = MyNodeId(); int node_num = NumberOfNodes(); long long int pocz = 1, minimum = inf; long long int koniec = PipeHeight(); if(me > 0) { Receive(me - 1); pocz = GetLL(me - 1); minimum = GetLL(me - 1); } for(int i = 0; i < (int)(std::min(range, koniec - pocz + 1)); i++) { minimum = std::min(minimum, HoleDiameter(((long long)i) + pocz)); minis[i] = minimum; //printf("%lld %lld\n", minis[i], minimum); } long long int j = 1; if(me < node_num - 1) { PutLL(me + 1, pocz + std::min(range, koniec - pocz + 1)); PutLL(me + 1, minimum); Send(me + 1); Receive(me + 1); j = GetLL(me + 1); } if(pocz < koniec && j <= NumberOfDiscs()) { long long disc_size = DiscDiameter(j); for(int i = (int)(std::min(range, koniec - pocz + 1)) - 1; i >= 0; i--) { //printf("%d %lld %lld\n", i, j, disc_size); if(minis[i] >= disc_size) { j++; if(j <= NumberOfDiscs()) disc_size = DiscDiameter(j); else { printf("%lld\n", ((long long)i) + pocz); break; } } } } if(me > 0) { PutLL(me - 1, j); Send(me - 1); } else { if(j <= NumberOfDiscs()) printf("0\n"); } return 0; } |