湖大训练赛第十场 Battleship

Battleship
Time Limit: 2000ms, Special Time Limit:5000ms, Memory Limit:262144KB
Total submit users: 16, Accepted users: 11
Problem 12906 : Special judge
Problem 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 10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 100 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 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 long

using 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;
}


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值