#include <iostream>
#include "message.h"
#include "dzialka.h"
using namespace std;
long long policz(int H, int x,int dlugosc_boku){
long long wynik=0;
int modul=0;
for (int i=0;i<H;i++){
int d=0;
for (int j=0;j<dlugosc_boku;j++){
if (IsUsableCell(i,x+j)==1) d=1;
else {
d=0;
break;
}
}
if (d==1) {
modul++;
wynik+=modul;
}
else{
modul=0;
}
}
return wynik;
}
int main() {
int H=GetFieldHeight();
int W=GetFieldWidth();
long long wynik=0;
int k;
if (H<W) k=H;
else k=W;
if (NumberOfNodes()<k) k=NumberOfNodes();
int MN=MyNodeId();
if (MN<k){
for (int dlugosc_boku=1;dlugosc_boku<=W;dlugosc_boku++)
{
for (int i=MN;i<W-dlugosc_boku+1;i+=k){
wynik+=policz(H,i, dlugosc_boku);
}
}
if (MN==0){
for (int i=1;i<k;i++){
Receive(i);
wynik+=GetLL(i);
}
cout<<wynik;
}
else{
PutLL(0, wynik);
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 | #include <iostream> #include "message.h" #include "dzialka.h" using namespace std; long long policz(int H, int x,int dlugosc_boku){ long long wynik=0; int modul=0; for (int i=0;i<H;i++){ int d=0; for (int j=0;j<dlugosc_boku;j++){ if (IsUsableCell(i,x+j)==1) d=1; else { d=0; break; } } if (d==1) { modul++; wynik+=modul; } else{ modul=0; } } return wynik; } int main() { int H=GetFieldHeight(); int W=GetFieldWidth(); long long wynik=0; int k; if (H<W) k=H; else k=W; if (NumberOfNodes()<k) k=NumberOfNodes(); int MN=MyNodeId(); if (MN<k){ for (int dlugosc_boku=1;dlugosc_boku<=W;dlugosc_boku++) { for (int i=MN;i<W-dlugosc_boku+1;i+=k){ wynik+=policz(H,i, dlugosc_boku); } } if (MN==0){ for (int i=1;i<k;i++){ Receive(i); wynik+=GetLL(i); } cout<<wynik; } else{ PutLL(0, wynik); Send(0); } } return 0; } |
English