NC25221. Mesh
描述
MINIEYE's engineer M is playing a game. In the game M has a grid base consists of 6 rows and 6 columns, and the enemy will continually shoot dominos to M. Domino also consists of squares, it can either be 1 row and 3 columns, 2 rows and 3 columns, 3 rows and 2 columns, or 3 rows and 1 column.
The square size of dominos and the grid base is the same. The grid base is empty at first, M will fill the grid base with dominos each time he gets them from the enemy.
The squares of dominos must fully cover the blank squares of the grid base. If all squares of a row or a column in the base are covered by dominos, then all dominos in that certain row or column will disappear, as shown below:
Fill the base with an orange domino of 2 rows and 3 columns, and put a blue domino of 1 row and 3 columns, then dominos on the third row will disappear. You can still put other dominos on the third row next time.
Please note that dominos cannot overlap with each other; Meanwhile, dominos sent by the enemy cannot rotate, for example, a domino of 1 row and 3 columns cannot be changed to a domino of 3 rows and 1 column. Enemy wins the game if any dominos sent by him cannot be placed in the base; otherwise M wins if all dominos can be successfully filled in the grid base.
How can M win the game?
输入描述
The input only has one string consisting of 0, 1, 2 and 3; the length of the string will be within [1, 5×105].
If the character is 0, then it's a domino of 1 row and 3 columns; if it's 1, it's a domino of 2 rows and 3columns; if it's 2, it's a domino of 3 rows and 2 columns; if it's 3, it's a domino of 3 rows and 1 column.
输出描述
You need todescribe where each domino should be placed.
Output |s|rows, for the ith row, output two integers r and c which means the upper leftsquare of the ith domino should align with the rth row and the cth column ofthe grid base. Rows and columns are numbered from 1, which means 1 ≤ r, c ≤ 6.
If there aremore than one solutions, please output any of them.
If there is nosolution, please print -1.
示例1
输入:
02120113
输出:
1 1 2 1 5 1 1 1 4 1 2 3 5 1 4 4
说明:
Then the first two columns disappear, and after thenext 3 tiles are placed, the grid looks like below.
Then the third column disappear, after the next onetile is placed, the grid looks like below.
Then the first two columns disappear, after the lastone tile is placed, the grid looks like below.
Massiveinput, please notice.
C++11(clang++ 3.9) 解法, 执行用时: 83ms, 内存消耗: 3424K, 提交时间: 2019-04-23 20:58:44
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; char s[maxn]; int main() { scanf("%s", s); int c0 = 0, c1 = 0, c2 = 1, c3 = 1; for(int i = 0; s[i]; i++) { if(s[i] == '0') printf("%d %d\n", 1, c0 * 3 + 1), c0 ^= 1; else if(s[i] == '1') printf("%d %d\n",2, c1 * 3 + 1), c1 ^= 1; else if(s[i] == '3') printf("%d %d\n", c2 * 3 + 1, 4), c2 ^= 1; else if(s[i] == '2') printf("%d %d\n", c3 * 3 + 1, 5), c3 ^= 1; } return 0; }
C++14(g++5.4) 解法, 执行用时: 121ms, 内存消耗: 3548K, 提交时间: 2019-05-03 22:24:57
#include<bits/stdc++.h> using namespace std; char s[500005]; int main() { bool v1,v2,v3,v4; v1=0,v2=0,v3=1,v4=1; scanf("%s",s); int len=strlen(s); for(int i=0;i<len;i++){ if(s[i]=='2') printf("%d %d\n",3*v1+1,1),v1=!v1; else if(s[i]=='3') printf("%d %d\n",3*v2+1,3),v2=!v2; else if(s[i]=='1') printf("%d %d\n",5,3*v3+1),v3=!v3; else printf("%d %d\n",4,3*v4+1),v4=!v4; } return 0; }