#include <iostream> #include "krazki.h" #include "message.h" #define ll long long int using namespace std; ll min(ll a, ll b) { if (a < b) { return a; } else { return b; } } int main() { if (MyNodeId() == 0) { int n, m; ll *tube, *disk; n = PipeHeight(); m = NumberOfDiscs(); tube = new ll[n + 1]; disk = new ll[m + 1]; ll current = (ll) 1000000000000000000 + 1; for (int i = 1; i <= n; i++) { ll temp = HoleDiameter(i); tube[i] = min(current, temp); current = min(current, tube[i]); } for (int i = 1; i <= m; i++) { disk[i] = DiscDiameter(i); } int deep = n; for (int i = 1; i <= m; i++) { if (deep == 0 || tube[1] < disk[i]) { cout << 0; delete[] tube; delete[] disk; return 0; } while (deep >= 1 && tube[deep] < disk[i]) { deep--; } deep--; } cout << deep + 1; delete[] tube; delete[] disk; } 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 | #include <iostream> #include "krazki.h" #include "message.h" #define ll long long int using namespace std; ll min(ll a, ll b) { if (a < b) { return a; } else { return b; } } int main() { if (MyNodeId() == 0) { int n, m; ll *tube, *disk; n = PipeHeight(); m = NumberOfDiscs(); tube = new ll[n + 1]; disk = new ll[m + 1]; ll current = (ll) 1000000000000000000 + 1; for (int i = 1; i <= n; i++) { ll temp = HoleDiameter(i); tube[i] = min(current, temp); current = min(current, tube[i]); } for (int i = 1; i <= m; i++) { disk[i] = DiscDiameter(i); } int deep = n; for (int i = 1; i <= m; i++) { if (deep == 0 || tube[1] < disk[i]) { cout << 0; delete[] tube; delete[] disk; return 0; } while (deep >= 1 && tube[deep] < disk[i]) { deep--; } deep--; } cout << deep + 1; delete[] tube; delete[] disk; } return 0; } |