#include "dzialka.h"
#include "message.h"
#include <math.h>
#include <iostream>
/*
int GetFieldHeight(); – zwraca wysokość zakupionego pola.
int GetFieldWidth(); – zwraca szerokość zakupionego pola.
int IsUsableCell(int r, int c); – dla podanych 0 ≤ r < GetFieldHeight(), 0 ≤ c < GetFieldWidth()
zwraca 1, jeśli kwadracik o współrzędnych (r, c) jest użytkowy lub 0 w przeciwnym przypadku.
*/
using namespace std;
int main(){
const int NumRows = GetFieldHeight();
const int NumCols = GetFieldWidth();
int start = MyNodeId() * 750;
int end = start + 750;
if (end > NumCols) end = NumCols;
long long int ans = 0;
for (int i = start ; i<fmin(end, NumCols) ; i++){ // cols
for (int j = 0 ; j<NumRows ; j++){ // rows
// sprawdzamy prostokaty o lewym dolnym rogu w (i, j)
for (int a = 1 ; a < NumCols ; a++){
for (int b=1 ; b < NumRows ; b++){
bool isRect = true;
for (int x = i ; x < fmin(i+a, NumCols) ; x++){
for (int y=j ; y< fmin(j+b, NumRows) ; y++){
if (IsUsableCell(x, y)==0) {
isRect = false;
break;
}
}
}
if (isRect) ans++;
}
}
}
}
long long int result = 0;
if (MyNodeId() > 0) {
PutLL(0, ans);
Send(0);
} else { // MyNodeId == 0
result += ans;
for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) {
Receive(instancja);
result += GetLL(instancja);
}
cout << "16" << 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 53 54 55 56 57 58 | #include "dzialka.h" #include "message.h" #include <math.h> #include <iostream> /* int GetFieldHeight(); – zwraca wysokość zakupionego pola. int GetFieldWidth(); – zwraca szerokość zakupionego pola. int IsUsableCell(int r, int c); – dla podanych 0 ≤ r < GetFieldHeight(), 0 ≤ c < GetFieldWidth() zwraca 1, jeśli kwadracik o współrzędnych (r, c) jest użytkowy lub 0 w przeciwnym przypadku. */ using namespace std; int main(){ const int NumRows = GetFieldHeight(); const int NumCols = GetFieldWidth(); int start = MyNodeId() * 750; int end = start + 750; if (end > NumCols) end = NumCols; long long int ans = 0; for (int i = start ; i<fmin(end, NumCols) ; i++){ // cols for (int j = 0 ; j<NumRows ; j++){ // rows // sprawdzamy prostokaty o lewym dolnym rogu w (i, j) for (int a = 1 ; a < NumCols ; a++){ for (int b=1 ; b < NumRows ; b++){ bool isRect = true; for (int x = i ; x < fmin(i+a, NumCols) ; x++){ for (int y=j ; y< fmin(j+b, NumRows) ; y++){ if (IsUsableCell(x, y)==0) { isRect = false; break; } } } if (isRect) ans++; } } } } long long int result = 0; if (MyNodeId() > 0) { PutLL(0, ans); Send(0); } else { // MyNodeId == 0 result += ans; for (int instancja = 1; instancja < NumberOfNodes(); ++instancja) { Receive(instancja); result += GetLL(instancja); } cout << "16" << endl; } return 0; } |
English