LuoguP4420 [COCI2017-2018#1] Tetris 題解
阿新 • • 發佈:2021-12-16
LuoguP4420 [COCI2017-2018#1] Tetris 題解
種情況進行暴力判斷就好了。抓住這些圖形的特徵,並轉化成程式碼語言就能夠迎刃而解。
Content
有一個 \(n\times m\) 的拼圖,擺上了幾塊俄羅斯方塊圖形。已知這些圖形可能包含以下這五種(可以旋轉),求出下列型別的俄羅斯方塊圖形數量。
資料範圍:\(1\leqslant n,m\leqslant 10\)。
Solution
像我這樣菜的人,這種題目只有一種方法:暴力判斷。
各位玩過俄羅斯方塊的都知道,上面 \(5\) 種圖形中,第一種圖形無論怎麼旋轉都是一樣的,第二、三、四種都可以通過旋轉得到兩種不同的圖形,第五種可以通過旋轉得到 \(4\) 種不同的圖形。具體是什麼樣的想必各位都能夠想象得出來。
於是,我們只需要對這總共 \(1+2\times 3+4=11\)
然而最煩人的就是打程式碼的過程……
Code
僅搬出判斷五種不同型別的圖形的函式 \(\texttt{judge1}\sim\texttt{judge5}\),畢竟這才是整個程式碼的精髓,也是我打得最要命的地方……
inline bool judge1(int i, int j) {return a[i][j] != '.' && (a[i][j] == a[i + 1][j] && a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i][j + 1]);} inline bool judge2(int i, int j) {return a[i][j] != '.' && ((a[i][j] == a[i][j + 1] && a[i][j] == a[i][j + 2] && a[i][j] == a[i][j + 3]) || (a[i][j] == a[i + 1][j] && a[i][j] == a[i + 2][j] && a[i][j] == a[i + 3][j]));} inline bool judge3(int i, int j) {return a[i][j] != '.' && ((a[i][j] == a[i][j - 1] && a[i][j] == a[i + 1][j - 1] && a[i][j] == a[i + 1][j - 2]) || (a[i][j] == a[i + 1][j] && a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i + 2][j + 1]));} inline bool judge4(int i, int j) {return a[i][j] != '.' && ((a[i][j] == a[i][j + 1] && a[i][j] == a[i + 1][j + 1] && a[i][j] == a[i + 1][j + 2]) || (a[i][j] == a[i + 1][j] && a[i][j] == a[i + 1][j - 1] && a[i][j] == a[i + 2][j - 1]));} inline bool judge5(int i, int j) {return a[i][j] != '.' && ((a[i][j] == a[i + 1][j - 1] && a[i][j] == a[i + 1][j] && a[i][j] == a[i + 1][j + 1]) || (a[i][j] == a[i - 1][j - 1] && a[i][j] == a[i][j - 1] && a[i][j] == a[i + 1][j - 1]) || (a[i][j] == a[i - 1][j - 1] && a[i][j] == a[i - 1][j] && a[i][j] == a[i - 1][j + 1]) || (a[i][j] == a[i - 1][j + 1] && a[i][j] == a[i][j + 1] && a[i][j] == a[i + 1][j + 1]));}