// Jedna instancja wypisuje maksymalny wzrost. #include "message.h" #include "teatr.h" #include "bits/stdc++.h" using namespace std; int main() { double nodes = 100.0; int n = GetN(); double z = n / nodes; int s = z * MyNodeId(); int e = z * (MyNodeId() + 1); long long R[6] = {0}; long long r = 0; for (int i = s; i < e; i++) { int el = GetElement(i); for (int j = el+1; j < 6; j++) { r += R[j]; } R[el]++; } if (MyNodeId() == 0) { for (int i = 1; i < 100; i++) { Receive(i); long long a = GetLL(i); r += a; for (int j = 0; j < 6; j++) { long long x=GetLL(i); R[j] += x; for (int k = j + 1; k < 6; k++) { r += R[k]; } } } cout << r << endl; } else { PutLL(0, r); for (int k = 0; k < 6; k++) { PutLL(0, R[k]); } Send(0); } 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 | // Jedna instancja wypisuje maksymalny wzrost. #include "message.h" #include "teatr.h" #include "bits/stdc++.h" using namespace std; int main() { double nodes = 100.0; int n = GetN(); double z = n / nodes; int s = z * MyNodeId(); int e = z * (MyNodeId() + 1); long long R[6] = {0}; long long r = 0; for (int i = s; i < e; i++) { int el = GetElement(i); for (int j = el+1; j < 6; j++) { r += R[j]; } R[el]++; } if (MyNodeId() == 0) { for (int i = 1; i < 100; i++) { Receive(i); long long a = GetLL(i); r += a; for (int j = 0; j < 6; j++) { long long x=GetLL(i); R[j] += x; for (int k = j + 1; k < 6; k++) { r += R[k]; } } } cout << r << endl; } else { PutLL(0, r); for (int k = 0; k < 6; k++) { PutLL(0, R[k]); } Send(0); } return 0; } |