// Błędne rozwiązanie do zadania Działka 2. // Na pojedynczym węźle wypisuje liczbę dostępnych kwadracików. #include "dzialka.h" #include "message.h" #include <iostream> int main() { if (MyNodeId() > 0) return 0; const int NumRows = GetFieldHeight(); const int NumCols = GetFieldWidth(); int pref[NumRows + 1][NumCols + 1]; bool p[NumRows + 1][NumCols + 1]; for (int Row = 0; Row < NumRows; ++Row) for (int Col = 0; Col < NumCols; ++Col) pref[Row][Col] = 0, p[Row][Col] = 0; long long Result = 0; for (int Row = 0; Row < NumRows; ++Row) for (int Col = 0; Col < NumCols; ++Col) if (IsUsableCell(Row, Col)) ++pref[Row][Col]; for(int Row = 0; Row < NumRows; ++Row) for(int Col = 0; Col < NumCols; ++Col) { if(Row) pref[Row][Col] += pref[Row - 1][Col]; if(Col) pref[Row][Col] += pref[Row][Col - 1]; if(Row && Col) pref[Row][Col] -= pref[Row - 1][Col - 1]; } for(int Row = 0; Row < NumRows; ++Row) { for(int Col = 0; Col < NumCols; ++Col) { if(p[Row][Col]) { for(int i = 0; i <= Row; ++i) { for(int j = 0; j <= Col; ++j) { int p1 = (Row - i + 1) * (Col - j + 1), p2 = pref[Row][Col]; if(i) p2 -= pref[i - 1][j]; if(j) p2 -= pref[i][j - 1]; if(i && j) p2 += pref[i - 1][j - 1]; if(p1 == p2) Result++; } } } } } std::cout << Result << "\n"; }
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 | // Błędne rozwiązanie do zadania Działka 2. // Na pojedynczym węźle wypisuje liczbę dostępnych kwadracików. #include "dzialka.h" #include "message.h" #include <iostream> int main() { if (MyNodeId() > 0) return 0; const int NumRows = GetFieldHeight(); const int NumCols = GetFieldWidth(); int pref[NumRows + 1][NumCols + 1]; bool p[NumRows + 1][NumCols + 1]; for (int Row = 0; Row < NumRows; ++Row) for (int Col = 0; Col < NumCols; ++Col) pref[Row][Col] = 0, p[Row][Col] = 0; long long Result = 0; for (int Row = 0; Row < NumRows; ++Row) for (int Col = 0; Col < NumCols; ++Col) if (IsUsableCell(Row, Col)) ++pref[Row][Col]; for(int Row = 0; Row < NumRows; ++Row) for(int Col = 0; Col < NumCols; ++Col) { if(Row) pref[Row][Col] += pref[Row - 1][Col]; if(Col) pref[Row][Col] += pref[Row][Col - 1]; if(Row && Col) pref[Row][Col] -= pref[Row - 1][Col - 1]; } for(int Row = 0; Row < NumRows; ++Row) { for(int Col = 0; Col < NumCols; ++Col) { if(p[Row][Col]) { for(int i = 0; i <= Row; ++i) { for(int j = 0; j <= Col; ++j) { int p1 = (Row - i + 1) * (Col - j + 1), p2 = pref[Row][Col]; if(i) p2 -= pref[i - 1][j]; if(j) p2 -= pref[i][j - 1]; if(i && j) p2 += pref[i - 1][j - 1]; if(p1 == p2) Result++; } } } } } std::cout << Result << "\n"; } |