[BZOJ1501] [NOI2005] Chihuizhu Games

Source: Internet
Author: User

Input

The file contains the initial description of the disk, a total of 10 lines, line I has I characters. If the J character of Line I is one of the letters "a" to "L", then the part is already placed on the lattice in column J of Line I, and the part number is the corresponding letter. If the J-character of Line I is ".", then the part is not placed on the lattice in column J of row No. I. The input guarantees that the pre-release parts are placed in the disc.

Output

If you can find the solution, print 10 lines to the output file for the layout after all 12 parts have been placed. The line I shall contain I characters, and the J character of line I indicates which part is placed on the lattice of column J of row I. If there is no solution, output a single string of ' no solution ' (no quotation marks, please note the case). All data guarantees a maximum of one set of solutions.

Sample Input.
..
...
....
.....
..... C
... Ccc.
Eeehh ...
E.hhh ....
E.........

Sample Output B
Bk
BKK
Bjkk
Jjjdd
Gjgddc
Gggccci
Eeehhiia
Elhhhiaaf
Elllliffff
Note: The surface suggested that we go to Bzoj official website to see, because the format of the problem here the picture can only be so small. Bzoj 1051:http://www.lydsy.com/judgeonline/problem.php?id=1501 The following: There's really nothing to say ... Although I said that the exam in the school I wrote 80 points (10 points is forget no solution. No words), but there is no guarantee in the examination room can have such a good mentality to write a 2-hour! We take each direction of each pattern, remembering the point in the upper-left corner as the origin, and recording the relative relationship of the other points. It is then possible to make judgments on the map in a position. The idea is not complicated, but record other points relative relation this part, write ugly can write a few 10k+, write good also want 6k. But if that's the case, it's only 90 points. Because there is a data point intentional card! I think the data is really unknown, the kind of card is inexplicable, because he has placed the Chihuizhu in the lower right, there is only one, all the front part of the search time is particularly long, so the map to change the direction. Who's going to think like that? And even if it does, in fact, if I put the only one Chihuizhu in the lower left corner, there is no way to pass, so this question still has a lot of doubts. There is another way is dacing-link, I did not go to understand, you can check the Internet, you will find that the problem has been found, so there is no point. code (90 points):------------------------------------------------------------------------------------------------------

#include <cstdio>
#include <cstdlib>
#define MAXN 15
#define Dfs_next if (y = = x) DFS (x + 1, 1); else DFS (x, y + 1)

const int A[100][6] = {
{0, 0, 0, 0, 0, 0},

{0, 1, 0, 0, 0, 0}, {0, 1, 0,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0};

int VIS[MAXN][MAXN], MAP[MAXN][MAXN], USE[MAXN];

BOOL Out (int o) {return o < 1 | | o > 10;}

bool Check (int o, int x, int y)
{
if (Inv[o]) return 0;
for (int i = 1; i < tot[o]; i++)
{
int dx = x + a[o][i], dy = y + b[o][i];
if (out (dx) | | (DY)) return 0;
if (Vis[dx][dy]) return 0;
}
return 1;
}

void DFS (int x, int y)
{
if (x = = && y = = 1)
{
for (int i = 1; i <=; i++)
{
for (int j = 1; J <= I; j + +) printf ("%c", Map[i][j] + ' A '-1);
printf ("\ n");
}
exit (0);
}
if (Vis[x][y]) {dfs_next;}
else for (int i = 1; i <=; i++)
{
if (use[i]) continue;
For (int j = 0; J <= 7; j + +)
{
int o = i * 8-J;
if (check (o, x, y))
{
for (int k = 0; k < tot[o]; k++)
vis[x + a[o][k]][y + b[o][k]] = 1, map[x + A[o][k]][y + b[o][k]] = i;
Use[i] = 1; Dfs_next; Use[i] = 0;
for (int k = 0; k < tot[o]; k++) vis[x + a[o][k]][y + b[o][k]] = 0;
}
}
}
}

Char CH[MAXN];

int main ()
{
freopen ("game.in", "R", stdin);
freopen ("Game.out", "w", stdout);
for (int i = 1; i <=; i++)
{
scanf ("%s", ch);
For (int j = 0; J <= I-1; j + +)
{
if (ch[j] = = '. ') Map[i][j + 1] = 0;
else Map[i][j + 1] = ch[j]-' a ' + 1, vis[i][j + 1] = 1, use[ch[j]-' a ' + 1] = 1;
}
}
for (int i = 1; i <=; i++)
For (int j = Ten; J > i; j--) vis[i][j] = 1;
DFS (a);
printf ("No solution");
return 0;
}

------------------------------------------------------------------------------------------------------

[BZOJ1501] [NOI2005] Chihuizhu Games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.