Question link: http://acm.hnu.cn/online? Action = problem & type = show & id = 12906.
Solution report: I have not understood the meaning of the question for a long time. It is a 10*10 square, and some ships will be placed on it. The ship's specifications are one ship with four grids, respectively, two ships occupy three grids, three of which occupy two grids, and four of which occupy one grid. The input is a matrix of 10x10, and the numbers are all numbers ranging from 1 to. The number indicates the time at which the ship will be hit. When every grid in a ship is hit, the ship will sink, requiring that the two ships cannot be adjacent, and then asking you to find the most complicated arrangement of the ship, that is, what is the most complex arrangement method here, the truth is, it turns out that you need to find out that there is no ship arrangement method at the end of the matrix. This is not to say that the ship must be placed at the position of 100.
1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 7 int map[11][11]; 8 char ans[11][11],temp[11][11]; 9 10 int main()11 {12 // freopen("in.txt","r",stdin);13 for(int i = 1;i <= 10;++i)14 for(int j = 1;j <= 10;++j)15 {16 scanf("%d",&map[i][j]);17 ans[i][j] = temp[i][j] = ‘.‘;18 }19 ans[1][1] = ans[1][3] = ans[1][5] = ‘#‘;20 ans[2][1] = ans[2][2] = ‘#‘;21 ans[2][4] = ans[2][5] = ‘#‘;22 ans[2][7] = ans[2][8] = ‘#‘;23 ans[3][1] = ans[3][2] = ans[3][3] = ‘#‘;24 ans[3][5] = ans[3][6] = ans[3][7] = ‘#‘;25 ans[4][1] = ans[4][2] = ans[4][3] = ans[4][4] = ‘#‘;26 int x,y;27 for(int i = 1;i <= 10;++i)28 for(int j = 1;j <= 10;++j)29 if(map[i][j] == 100)30 {31 x = i,y = j;32 temp[i][j] = ‘#‘;33 break;34 }35 int f = 1;36 for(int i = (x&1)? 1:2;i <= 10;i+=2)37 if(abs(i-x) > 1)38 {39 for(int j = 1;j <= 10;++j)40 temp[i][j] = ans[f][j];41 f++;42 if(f > 4) break;43 }44 for(int i = 1;i <= 10;++i)45 {46 temp[i][11] = NULL;47 puts(temp[i]+1);48 }49 return 0;50 }
View code