#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include "kollib.h"
#include "message.h"
using namespace std;
inline int min(const int a, const int b)
{
return a < b ? a : b;
}
int main()
{
if (MyNodeId())
return 0;
#if 0
const int n = NumberOfStudents();
int* tab = new int[n + 1];
for (int i = 1; i <= n; i++)
tab[i] = -1;
int curr = tab[1] = 1;
for (int i = 2; i <= n; i++)
{
const int neighbor0 = FirstNeighbor(curr);
if (tab[neighbor0] == -1)
{
tab[curr = neighbor0] = i;
}
else
{
const int neighbor1 = SecondNeighbor(curr);
tab[curr = neighbor1] = i;
}
}
const int q = NumberOfQueries();
for (int i = 1; i <= q; i++)
{
const int p0 = tab[ QueryFrom(i) ];
const int p1 = tab[ QueryTo(i) ];
const int dist = p0 < p1 ? p1 - p0 : p0 - p1;
const int nearerDist = min(dist, n - dist);
cout << nearerDist << endl;
}
#else
const int n = 500 * 1000 * 1000;
for (int i = 1; i <= n; i++)
{
FirstNeighbor(1);
SecondNeighbor(1);
}
#endif
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 | #include <stdio.h> #include <stdlib.h> #include <iostream> #include "kollib.h" #include "message.h" using namespace std; inline int min(const int a, const int b) { return a < b ? a : b; } int main() { if (MyNodeId()) return 0; #if 0 const int n = NumberOfStudents(); int* tab = new int[n + 1]; for (int i = 1; i <= n; i++) tab[i] = -1; int curr = tab[1] = 1; for (int i = 2; i <= n; i++) { const int neighbor0 = FirstNeighbor(curr); if (tab[neighbor0] == -1) { tab[curr = neighbor0] = i; } else { const int neighbor1 = SecondNeighbor(curr); tab[curr = neighbor1] = i; } } const int q = NumberOfQueries(); for (int i = 1; i <= q; i++) { const int p0 = tab[ QueryFrom(i) ]; const int p1 = tab[ QueryTo(i) ]; const int dist = p0 < p1 ? p1 - p0 : p0 - p1; const int nearerDist = min(dist, n - dist); cout << nearerDist << endl; } #else const int n = 500 * 1000 * 1000; for (int i = 1; i <= n; i++) { FirstNeighbor(1); SecondNeighbor(1); } #endif return 0; } |
English