#include #include #include #include #include #include #include using namespace std; typedef unsigned int uint; typedef long long LL; typedef vector VI; typedef vector VVI; typedef vector VVVI; typedef vector VVVVI; #define FOR(k,a,b) for(uint k(a); k < (b); ++k) #define REP(k,a) for(uint k=0; k < (a); ++k) int figureC[19] = { 1,1,2,1,3,1,4,1,5,2,3,3,3,3,3,2,2,2,2 }; int figureR[19] = { 1,2,1,3,1,4,1,5,1,2,3,3,3,3,3,2,2,2,2 }; VI disappearR(10), disappearC(10); VVVI figure; int calc(VVI& table, int actFig, int posR, int posC) { REP(o, figureC[actFig]) REP(p, figureR[actFig]) if ((figure[actFig].empty() || figure[actFig][p][o]) && table[posR + p][posC + o]) { return 0; } REP(o, figureC[actFig]) REP(p, figureR[actFig]) if ((figure[actFig].empty() || figure[actFig][p][o]) ) { table[posR + p][posC + o] = 1; } //check disappear fill(disappearR.begin(), disappearR.end(), 1); fill(disappearC.begin(), disappearC.end(), 1); REP(i, 10) { REP(j, 10) { if (!table[i][j]) { disappearR[i] = 0; disappearC[j] = 0; } } } int score = 100000; REP(i, 10) { if (disappearR[i]) { score += 1e7; } if (disappearC[i]) { score += 1e7; } } REP(i, 10) REP(j, 10) if(table[i][j]) { int nneighCtr = 0; FOR(ii, -1, 2) if (i + ii > -1 && i + ii<10) FOR(jj, -1, 2) if ((ii == 0 || jj==0) && j + jj > -1 && j + jj<10) { if (!table[i + ii][j + jj]) ++nneighCtr; } score -= nneighCtr*nneighCtr; } REP(o, figureR[actFig]) REP(p, figureC[actFig]) if ((figure[actFig].empty() || figure[actFig][o][p])) { table[posR + o][posC + p] = 0; } return score; } int main(int argc, char** argv) { #ifdef HOME freopen("in.txt", "rb", stdin); freopen("out.txt", "wb", stdout); #endif figure.resize(19); figure[11] = { { 1,1,1 },{ 0,0,1 },{ 0,0,1 } }; figure[12] = { { 0,0,1 },{ 0,0,1 },{ 1,1,1 } }; figure[13] = { { 1,0,0 },{ 1,0,0 },{ 1,1,1 } }; figure[14] = { { 1,1,1 },{ 1,0,0 },{ 1,0,0 } }; figure[15] = { { 1,1 },{ 1,0 } }; figure[16] = { { 1,1 },{ 0,1 } }; figure[17] = { { 0,1 },{ 1,1 } }; figure[18] = { { 1,0 },{ 1,1 } }; VVI table(10, VI(10)); int scoreR = 0, scoreC = 0, figput = 0; int fig[3]; int loop = 0; while (++loop) { scanf("%d %d %d", &fig[0], &fig[1], &fig[2]); //if(loop <= 10) // fprintf(stderr, "fig[0]: %d ; fig[1]: %d ; fig[2] put: %d \n", fig[0], fig[1], fig[2]); if (fig[0] == -1) break; // try to put fig1 --fig[0];--fig[1];--fig[2]; bool succes = 1; vector used(3); REP(qq, 3) { int aq = -1, posR = -1, posC = -1, bs = 0; REP(q, 3) if (!used[q]) { int actFig = fig[q]; REP(i, 11 - figureR[actFig]) { REP(j, 11 - figureC[actFig]) { int as = calc(table, actFig, i, j); if (as > bs) { bs = as; aq = q; posR = i; posC = j; } } } } //fprintf(stderr, "posX: %d ; posY: %d ; q: %d \n", posR, posC, aq); if (posR != -1) { printf("%d %d %d ", aq + 1, posR + figureR[fig[aq]], posC + 1); //fprintf(stderr,"%d %d %d ", aq + 1, posR + 1, posC + 1); REP(o, figureR[fig[aq]]) REP(p, figureC[fig[aq]]) if (figure[fig[aq]].empty() || figure[fig[aq]][o][p]) { table[posR + o][posC + p] = 1; } used[aq] = 1; ++figput; } else { printf("-1 -1 -1 "); } //after put check fill(disappearR.begin(), disappearR.end(), 1); fill(disappearC.begin(), disappearC.end(), 1); REP(i, 10) { REP(j, 10) { if (!table[i][j]) { disappearR[i] = 0; disappearC[j] = 0; } } } REP(i, 10) { if (disappearR[i]) { ++scoreR; } if (disappearC[i]) { ++scoreC; } REP(j, 10) if (disappearR[i] || disappearC[j]) table[i][j] = 0; } } printf("\n"); fflush(stdout); bool ok = 1; REP(q, 3) if (!used[q]) ok = 0; if(!ok) break; } fprintf(stderr, "scorex: %d ; scorey: %d ; figure put: %d \n", scoreR, scoreC, figput); fflush(stderr); return 0; }