湖大训练赛第十场 Battleship

来源:互联网 发布:网络恶意诽谤刑法 编辑:程序博客网 时间:2024/05/01 11:29

BattleshipTime Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:262144KBTotal submit users: 16, Accepted users: 11Problem 12906 : Special judgeProblem description

You are in a computer security business. Recently one of your clients developed a new test designed to separate humans from programs. Your task is to test its efficiency.

The test is based on a variation of the Battleship game. This game is played on a ten by ten grid. Before the beginning of the test, you should place ten ships on this grid. Each ship is represented by a number of consecutive cells, arranged vertically or horizontally. You should place exactly one four-cell ship, two three-cell ships, three two-cell and four one-cell ships. No two ships should have any common or adjacent cells. They should not share a corner of a cell as well.

After the ships have been arranged, the test proceeds in a number of rounds. At each round one cell is announced to be “shot”. If this cell is occupied by a ship, this ship is considered to be “hit”. After each cell of a ship has been hit at least once, the ship sinks. The test ends after all the ships have sunk.

Let’s call the complexity of an arrangement the number of round it took to finish the tests. The idea is that humans would create much more complex arrangements than programs.

You have already figured out that the cells are shot in a predefined order, each cell being shot exactly once. Now you want to write a program that would create the most complex arrangement on the basis of the order in which the cells are shot.


Input

The input file consists of ten lines, containing ten numbers each. Each number represents the round at which the corresponding cell will be shot. All numbers are distinct and belong to the range 1...100.


Output

Output the optimal ship arrangement for the battleship test. Empty cells should be represented by the dot (‘.’), occupied cells should by represented by the number sign (‘#’).


Sample Input
1 2 3 4 5 6 7 8 9 1036 37 38 39 40 41 42 43 44 1135 64 65 66 67 68 69 70 45 1234 63 84 85 86 87 88 71 46 1333 62 83 96 97 98 89 72 47 1432 61 82 95 100 99 90 73 48 1531 60 81 94 93 92 91 74 49 1630 59 80 79 78 77 76 75 50 1729 58 57 56 55 54 53 52 51 1828 27 26 25 24 23 22 21 20 19
Sample Output
...####.............#....##...#.#.....#.........#....###.....#................#...#.....#......#..#.

题意:按照1-100的顺序打。有1艘4个格子的船,2艘3个格子的船,3艘2个格子的船,4艘1个格子的船。船每个格子都被打到一次就沉默了。问要使船最后沉没怎么安排船的位置。用#表示船。#不能相邻也不能有边角。就是右下也不行。

@darkdream 用枚举构造Accept.赞!

#include<vector>#include<list>#include<map>#include<set>#include<deque>#include<stack>#include<bitset>#include<algorithm>#include<functional>#include<numeric>#include<utility>#include<sstream>#include<iostream>#include<iomanip>#include<cstdio>#include<cmath>#include<cstdlib>#include<cstring>#include<ctime>#define LL long longusing namespace std;int mp[20][20];int check(int i,int j){    int sum = 0 ;    if(i <= 10 && i >= 1 && j <= 10 && j >=1 )    {       sum += mp[i+1][j] + mp[i][j] + mp[i-1][j] +mp[i][j+1] + mp[i][j-1] + mp[i+1][j+1] + mp[i+1][j-1] + mp[i-1][j+1] + mp[i-1][j-1] ;       if(sum == 0 )         return 1;        return 0 ;     }    return 0 ;}int ship[] = {0,4,3,3,2,2,2,1,1,1,1};int hs[20];int dfs(int x, int y , int k ,int dis){   if(k == 1 )       return  1;   if(dis == 1)   {      int tx = x + 1;       int ty = y;      if(check(tx,ty))      {          if(dfs(tx,ty,k-1,dis))          {             mp[tx][ty] =1 ;             return 1;          }      }else{          return 0 ;       }   }else if(dis == 2){      int tx = x -1;       int ty = y;      if(check(tx,ty))      {          if(dfs(tx,ty,k-1,dis))          {             mp[tx][ty] =1 ;             return 1;          }      }else{          return 0 ;       }      }else if(dis == 3){      int tx = x;       int ty = y+1;      if(check(tx,ty))      {          if(dfs(tx,ty,k-1,dis))          {             mp[tx][ty] =1 ;             return 1;          }      }else{          return 0 ;       }      }else {      int tx = x;       int ty = y-1;      if(check(tx,ty))      {          if(dfs(tx,ty,k-1,dis))          {             mp[tx][ty] =1 ;             return 1;          }      }else{          return 0 ;       }      }   return 0 ;}void solve(int x, int y ){   //printf("%d %d\n",x,y);   for(int i = 1;i <= 9 ;i ++)       if(hs[i] == 0 )       for(int j = 1;j <= 4 ;j ++)       {           if(dfs(x,y,ship[i],j))           {                mp[x][y] = 1;               hs[i] = 1;                return ;           }       }}int main(){    int temp ;     while(scanf("%d",&temp) != EOF)    {        memset(mp,0,sizeof(mp));        memset(hs,0,sizeof(hs));        if(temp == 100 )        {            mp[1][1] = 1;         }        for(int  i = 2;i <= 10;i ++)        {            scanf("%d",&temp);            if(temp == 100 )            {                mp[1][i] = 1;             }        }        for(int i = 2;i <= 10;i ++)        {            for(int j = 1;j <= 10; j ++)            {                scanf("%d",&temp);                if(temp == 100 )                {                   mp[i][j] = 1;                 }            }        }        for(int i =1;i <= 10;i ++)        {           for(int j = 1;j <= 10; j ++)           {              if(check(i,j))              {                  solve(i,j);              }           }        }        for(int i =1;i <= 10 ;i ++)        {    for(int j = 1;j <= 10 ;j ++)            {              if(mp[i][j])              {                printf("#");              }else printf(".");            }            printf("\n");        }    }    return 0;}


0 0
原创粉丝点击