1017: Fire Net

本文介绍了一个算法挑战,目标是在包含墙壁的城市地图上放置尽可能多的防御塔楼,这些塔楼可以互相射击但不能彼此摧毁。文章详细说明了合法配置的要求,并提供了一个示例程序来解决这个问题。

1017: Fire Net


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K998514Standard

Suppose that we have a square city with straight streets. A map of a city is a square board with n rows and n columns, each representing a street or a piece of wall.

A blockhouse is a small castle that has four openings through which to shoot. The four openings are facing North, East, South, and West, respectively. There will be one machine gun shooting through each opening.

Here we assume that a bullet is so powerful that it can run across any distance and destroy a blockhouse on its way. On the other hand, a wall is so strongly built that can stop the bullets.

The goal is to place as many blockhouses in a city as possible so that no two can destroy each other. A configuration of blockhouses is legal provided that no two blockhouses are on the same horizontal row or vertical column in a map unless there is at least one wall separating them. In this problem we will consider small square cities (at most 4x4) that contain walls through which bullets cannot run through.

The following image shows five pictures of the same board. The first picture is the empty board, the second and third pictures show legal configurations, and the fourth and fifth pictures show illegal configurations. For this board, the maximum number of blockhouses in a legal configuration is 5; the second picture shows one way to do it, but there are several other ways.

 

Your task is to write a program that, given a description of a map, calculates the maximum number of blockhouses that can be placed in the city in a legal configuration.

The input file contains one or more map descriptions, followed by a line containing the number 0 that signals the end of the file. Each map description begins with a line containing a positive integer n that is the size of the city; n will be at most 4. The next n lines each describe one row of the map, with a '.' indicating an open space and an uppercase 'X' indicating a wall. There are no spaces in the input file.

For each test case, output one line containing the maximum number of blockhouses that can be placed in the city in a legal configuration.

 

Sample Input

4
.X..
....
XX..
....
2
XX
.X
3
.X.
X.X
.X.
3
...
.XX
.XX
4
....
....
....
....
0

 

Sample Output

5
1
5
2
4

 


This problem is used for contest: 65 

 

 

 #include<stdio.h>
int n;
char map[10][10];
int max;
int xx[8]={1,1, -1,-1,0,0,1,-1};
int yy[8]={1,-1,1,-1,1,-1,0,0};
int check(int x,int y)//只和前面的比较  看是否满足题意
{
    int i,j;
    for(i=x-1;i>=0;i--) {if(map[i][y]=='+') return 0;if(map[i][y]=='X')break;}
    //for(i=x+1;i<n;i++) {if(map[i][y]=='+') return 0;if(map[i][y]=='X')break;}
    for(j=y-1;j>=0;j--) {if(map[x][j]=='+') return 0;if(map[x][j]=='X')break;}
    //for(j=y+1;j<n;j++) {if(map[x][j]=='+') return 0;if(map[x][j]=='X')break;}
    return 1;
}
void dfs(int x,int y,int step)
{
    if(y==n) {y=0;x++;}
    if(x==n) {if(step>max) max=step; return ;}
    if(map[x][y]=='.'&&check(x,y))
    {
        map[x][y]='+';
        dfs(x,y+1,step+1);
        map[x][y]='.';
    }
    dfs(x,y+1,step);
}

int main()
{
    int i,j;
    while(scanf("%d",&n)==1&&n)
    {
        for(i=0;i<n;i++)   scanf("%s",map[i]);
        max=0;
        dfs(0,0,0);
        printf("%d/n",max);
    }
    return 0;
}

报错:(mask3d) yc@DESKTOP-BBCG9DJ:/usr/local/cuda-11.8/targets/x86_64-linux/lib$ ls -d /usr/local/cuda* /usr/local/cuda /usr/local/cuda-11.1 /usr/local/cuda-11.6 /usr/local/cuda-11.8 /usr/local/cuda-11 /usr/local/cuda-11.3 /usr/local/cuda-11.7 (mask3d) yc@DESKTOP-BBCG9DJ:/usr/local/cuda-11.8/targets/x86_64-linux/lib$ nvcc --version nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2021 NVIDIA Corporation Built on Sun_Mar_21_19:15:46_PDT_2021 Cuda compilation tools, release 11.3, V11.3.58 Build cuda_11.3.r11.3/compiler.29745058_0 (mask3d) yc@DESKTOP-BBCG9DJ:/usr/local/cuda-11.8/targets/x86_64-linux/lib$ python main_instance_segmentation.py python: can't open file '/usr/local/cuda-11.8/targets/x86_64-linux/lib/main_instance_segmentation.py': [Errno 2] No such file or directory (mask3d) yc@DESKTOP-BBCG9DJ:/usr/local/cuda-11.8/targets/x86_64-linux/lib$ python /home/yc/workspace/Mask3D-main/main_instance_segmentation.py Traceback (most recent call last): File "/home/yc/workspace/Mask3D-main/main_instance_segmentation.py", line 8, in <module> from trainer.trainer import InstanceSegmentation, RegularCheckpointing File "/mnt/h/workspace/Mask3D-main/trainer/trainer.py", line 9, in <module> from torch_scatter import scatter_mean File "/home/yc/anaconda3/envs/mask3d/lib/python3.10/site-packages/torch_scatter/__init__.py", line 16, in <module> torch.ops.load_library(spec.origin) File "/home/yc/anaconda3/envs/mask3d/lib/python3.10/site-packages/torch/_ops.py", line 1295, in load_library ctypes.CDLL(path) File "/home/yc/anaconda3/envs/mask3d/lib/python3.10/ctypes/__init__.py", line 374, in __init__ self._handle = _dlopen(self._name, mode) OSError: /home/yc/anaconda3/envs/mask3d/lib/python3.10/site-packages/torch_scatter/_version_cuda.so: undefined symbol: _ZN3c1017RegisterOperatorsD1Ev (mask3d) yc@DESKTOP-BBCG9DJ:/usr/local/cuda-11.8/targets/x86_64-linux/lib$ pip list Package Version ----------------------- ---------------- absl-py 2.3.1 antlr4-python3-runtime 4.9.3 brotlicffi 1.0.9.2 certifi 2025.8.3 cffi 1.17.1 charset-normalizer 3.3.2 colorama 0.4.6 Cython 0.29.37 detectron2 0.6 dotenv 0.9.9 filelock 3.19.1 fire 0.7.1 frozenlist 1.7.0 fsspec 2025.9.0 future 1.0.0 gmpy2 2.2.1 grpcio 1.62.2 hydra-core 1.3.2 idna 3.10 importlib_metadata 8.7.0 Jinja2 3.1.6 joblib 1.5.2 lightning-utilities 0.15.2 loguru 0.7.3 Markdown 3.9 MarkupSafe 3.0.2 mpmath 1.3.0 natsort 8.4.0 networkx 3.4.2 numpy 2.2.6 omegaconf 2.3.0 packaging 25.0 pillow 11.3.0 pip 25.2 pointnet2 0.0.0 protobuf 4.25.3 pycparser 2.23 pyDeprecate 0.3.2 PySocks 1.7.1 python-dateutil 2.9.0.post0 python-dotenv 1.1.1 pytorch-lightning 2.0.0 pytz 2025.2 pyviz3d 0.4.0 PyYAML 6.0.2 requests 2.32.5 setuptools 80.9.0 six 1.17.0 sympy 1.14.0 tensorboard 2.20.0 tensorboard_data_server 0.7.0 termcolor 3.1.0 torch 1.12.1+cu113 torch-scatter 2.1.0+pt112cu113 torchmetrics 1.8.2 torchvision 0.13.1+cu113
最新发布
09-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值