Fire Net

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 13   Accepted Submission(s) : 5

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

Problem Description

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.

Input

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.

Output

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
#include<Iostream>//代码写的难看了点..........可再写的简便一点
using namespace std;
void bianli(int a[5][5],int i,int j)
{
int ss;
for(ss=i-1;ss>=1;ss--)
if(a[ss][j]!=50)
a[ss][j]=20;
else
break;
for(ss=i+1;ss<=4;ss++)
if(a[ss][j]!=50)
a[ss][j]=20;
else
break;
for(ss=j-1;ss>=1;ss--)
if(a[i][ss]!=50)
a[i][ss]=20;
else
break;
for(ss=j+1;ss<=4;ss++)
if(a[i][ss]!=50)
a[i][ss]=20;
else
break;
}
int main()
{
int a[5][5],i,j,k,n,m,ans,ss;
char s;
while(cin>>k&&k)
{
ans=0;
for(i=1;i<=k;i++)
for(j=1;j<=k;j++)
{cin>>s;
if(s=='.')
a[i][j]=0;
else
a[i][j]=50;
}
for(i=1;i<=k;i++)
for(j=1;j<=k;j++)
{
if(a[i][j]!=50)
{
for(ss=i-1;ss>=1;ss--)
if(a[ss][j]!=50)
a[i][j]++;
else
break;
for(ss=i+1;ss<=4;ss++)
if(a[ss][j]!=50)
a[i][j]++;
else
break;
for(ss=j-1;ss>=1;ss--)
if(a[i][ss]!=50)
a[i][j]++;
else
break;
for(ss=j+1;ss<=4;ss++)
if(a[i][ss]!=50)
a[i][j]++;
else
break;
} }
/*for(i=1;i<=k;i++)
{
for(j=1;j<=k;j++)
cout<<a[i][j]<<' ';
cout<<endl;}*/
for(n=0;n<=9;n++)
for(i=1;i<=k;i++)
for(j=1;j<=k;j++)
{if(a[i][j]==n)
{ bianli(a,i,j);
ans++;}}
cout<<ans<<endl; }
return 0;
}

Fire Net HDU的更多相关文章

  1. (匹配)Fire Net --hdu --1045

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  2. Fire Net HDU 1045

    简单深搜,可以完全暴力,不会超时的. #include<iostream> #include<cstring> #include<cmath> using name ...

  3. A - Fire Net - hdu 1045(二分图匹配)

    题意:一个阵地可以向四周扫射,求出来最多能修多少个阵地,墙不可以被扫射透,阵地不能同行或者或者列(有墙隔着例外) 分析:很久以前就做过这道题..当时是练习深搜来着,不过时间复杂度比较高,现在再看突然发 ...

  4. Fire Net HDU - 1045(二分匹配)

    把每一列中相邻的 .  缩为一个点 作为二分图的左边 把每一行中相邻的  .  缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉// ...

  5. Fire Net HDU - 1045 (二分图匹配)

    题意: 给出一张图,图中'X'表示wall,'.'表示空地,可以放置blockhouse同一条直线上只能有一个blockhouse,除非有wall 隔开,问在给出的图中最多能放置多少个blockhou ...

  6. KUANGBIN带你飞

    KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题    //201 ...

  7. [kuangbin带你飞]专题1-23题目清单总结

    [kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...

  8. ACM--[kuangbin带你飞]--专题1-23

    专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...

  9. hdu 1045 Fire Net(最小覆盖点+构图(缩点))

    http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS     Memory Limit:32768KB   ...

随机推荐

  1. 11gR2RAC环境DBCA创建一个数据库错误ORA-15055 ORA-15001

    11gR2RAC环境DBCA创建一个数据库错误ORA-15055 ORA-15001 象: 在11gR2 GridInfrastructure和Database软件安装完毕之后,运行DBCA创建数据库 ...

  2. 函数式编程很难,这正是你要学习它的原因 | 外刊IT评论网

    函数式编程很难,这正是你要学习它的原因 | 外刊IT评论网 函数式编程很难,这正是你要学习它的原因 156 次分享 新浪微博 腾讯微博 Tweet 人人网 QQ空间 很奇怪不是,很少有人每天都使用函数 ...

  3. OSG+VS2010+win7环境搭建

    Win7下 osg+vs2010环境搭建 一.相关准备 a) Osg源代码 当前最新版:OpenSceneGraph的3.0.0.zip 下载链接: http://www.openscenegraph ...

  4. [置顶] 一步一步学android之事件篇——下拉列表事件

    上一篇RadioGroup比较简单,所以再学习个spinner的OnItemSelectedListener事件,前面说过spinner的主要功能就是提供列表显示的选择,比如我们在选择城市的时候就会用 ...

  5. zoj3471(状压dp)

    题目连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4257 题意:不超过10种气体,两两之间相互碰撞可以产生一定的能量,如 ...

  6. 《火球——UML大战需求分析》(第1章 大话UML)——1.3 行为型的UML(Behavior Diagram)

    说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...

  7. Android---App Widget(一)

    本文译自:http://developer.android.com/guide/topics/appwidgets/index.html App Widgets是一些较小的应用程序窗口,它们能够被嵌入 ...

  8. WP开发使用BingMaps地图服务

    原文:WP开发使用BingMaps地图服务 WP8使用BingMaps地图在 SOAP服务如何计算路径 首先需要用到3个服务 1.GeoCode服务-转换地址到地理的经纬度(WebServices地址 ...

  9. 图像库---Image Datasets---OpenSift源代码---openSurf源代码

    1.Computer Vision Datasets on the web http://www.cvpapers.com/datasets.html 2.Dataset Reference http ...

  10. MYSQL经常使用命令列表

    MYSQL经常使用命令列表 1.系统管理 mysql -h主机地址 -uusername -p 连接MYSQL(在mysql/bin) exit 退出MYSQL命令 mysqladmin -uuser ...