#include <iostream>
#include <vector>
#include <cstdio>
#include "message.h"
#include "dzialka.h"
using namespace std;
int main()
{
int h=GetFieldHeight();
int w=GetFieldWidth();
long long suma=0;
int xxx=0;
for(int i=0; i<h; i+=NumberOfNodes())
{
for(int j=0; j<w; j++)
{
int kon=h;
for(int x=j; x<w; x++)
{
for(int y=MyNodeId()+xxx*NumberOfNodes(); y<kon; y++)
{
int p=IsUsableCell(y, x);
if(p==1) suma++;
else
{
kon=y;
}
}
if(kon==xxx) x=w;
}
}
xxx++;
}
if(MyNodeId!=0)
{
PutLL(0, suma);
Send(0);
}
else
{
for(int instancja=1; instancja<NumberOfNodes(); instancja++)
{
Receive(instancja);
suma+=GetLL(instancja);
}
cout << suma;
}
//cout << suma << endl;
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 | #include <iostream> #include <vector> #include <cstdio> #include "message.h" #include "dzialka.h" using namespace std; int main() { int h=GetFieldHeight(); int w=GetFieldWidth(); long long suma=0; int xxx=0; for(int i=0; i<h; i+=NumberOfNodes()) { for(int j=0; j<w; j++) { int kon=h; for(int x=j; x<w; x++) { for(int y=MyNodeId()+xxx*NumberOfNodes(); y<kon; y++) { int p=IsUsableCell(y, x); if(p==1) suma++; else { kon=y; } } if(kon==xxx) x=w; } } xxx++; } if(MyNodeId!=0) { PutLL(0, suma); Send(0); } else { for(int instancja=1; instancja<NumberOfNodes(); instancja++) { Receive(instancja); suma+=GetLL(instancja); } cout << suma; } //cout << suma << endl; return 0; } |
English