#include <iostream>
#include "message.h"
#include "kollib.h"
#include <cstdio>
using namespace std;
int n, m, start, koniec, inst, myinst, p, q, czas, a1, b1, gdzie1, a2, b2, gdzie2, ile, tab[201];
int main()
{
n=NumberOfStudents();
m=NumberOfQueries();
inst=NumberOfNodes();
myinst=MyNodeId();
p=(myinst*m)/inst;
q=((myinst+1)*m)/inst;
for(int z=p+1; z<=q; z++)
{
czas=0;
start=QueryFrom(z);
koniec=QueryTo(z);
if(start!=koniec)
{
gdzie1=FirstNeighbor(start);
gdzie2=SecondNeighbor(start);
czas++;
a1=a2=start;
while(gdzie1!=koniec && gdzie2!=koniec)
{
b1=FirstNeighbor(gdzie1);
b2=FirstNeighbor(gdzie2);
if(a1==b1)
b1=SecondNeighbor(gdzie1);
if(a2==b2)
b2=SecondNeighbor(gdzie2);
a1=gdzie1;
a2=gdzie2;
gdzie1=b1;
gdzie2=b2;
czas++;
}
if(myinst!=0)
PutInt(0, czas);
else
tab[z]=czas;
}
else
{
if(myinst!=0)
PutInt(0, czas);
else
tab[z]=czas;
}
}
if(myinst!=0 && p!=q)
Send(0);
if(myinst==0)
{
p=0;
q=m/inst;
if(inst>=m)
ile=inst-1;
else
{
if(p!=q)
ile=m-1;
else
ile=m;
}
for(int jest=0; jest<ile; jest++)
{
a1=Receive(-1);
p=(a1*m)/inst;
q=((a1+1)*m)/inst;
for(int v=p+1; v<=q; v++)
{
b1=GetInt(a1);
tab[v]=b1;
}
}
for(int po=1; po<=m; po++)
printf("%d\n", tab[po]);
}
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | #include <iostream> #include "message.h" #include "kollib.h" #include <cstdio> using namespace std; int n, m, start, koniec, inst, myinst, p, q, czas, a1, b1, gdzie1, a2, b2, gdzie2, ile, tab[201]; int main() { n=NumberOfStudents(); m=NumberOfQueries(); inst=NumberOfNodes(); myinst=MyNodeId(); p=(myinst*m)/inst; q=((myinst+1)*m)/inst; for(int z=p+1; z<=q; z++) { czas=0; start=QueryFrom(z); koniec=QueryTo(z); if(start!=koniec) { gdzie1=FirstNeighbor(start); gdzie2=SecondNeighbor(start); czas++; a1=a2=start; while(gdzie1!=koniec && gdzie2!=koniec) { b1=FirstNeighbor(gdzie1); b2=FirstNeighbor(gdzie2); if(a1==b1) b1=SecondNeighbor(gdzie1); if(a2==b2) b2=SecondNeighbor(gdzie2); a1=gdzie1; a2=gdzie2; gdzie1=b1; gdzie2=b2; czas++; } if(myinst!=0) PutInt(0, czas); else tab[z]=czas; } else { if(myinst!=0) PutInt(0, czas); else tab[z]=czas; } } if(myinst!=0 && p!=q) Send(0); if(myinst==0) { p=0; q=m/inst; if(inst>=m) ile=inst-1; else { if(p!=q) ile=m-1; else ile=m; } for(int jest=0; jest<ile; jest++) { a1=Receive(-1); p=(a1*m)/inst; q=((a1+1)*m)/inst; for(int v=p+1; v<=q; v++) { b1=GetInt(a1); tab[v]=b1; } } for(int po=1; po<=m; po++) printf("%d\n", tab[po]); } return 0; } |
English