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. XMPP协议简介

    XMPP(息处理现场协议)是基于可扩展标记语言(XML)的协议.它用于即时消息(IM)以及在线现场探測.XMPP协议採用的是client-server架构,全部从一个client发到还有一个clien ...

  2. 18.如何自我Struts2它Struts2标签和综合汇总文章有点早

    18.如何自我Struts2它Struts2标签和综合汇总文章有点早[视频] 之前写了一篇"打算做一个视频教程探讨怎样自学计算机相关的技术",优酷上传不了.仅仅好传到百度云上: h ...

  3. Samba &amp; Nginx - Resource temporarily unavailable

    先说说本人的开发环境:Win7 + Editplus + VMware(Centos+Samba+Nginx).用Samba在Centos上把web文件夹(如www)共享,然后在Win7上訪问这个文件 ...

  4. python(abi) RPM DEB Download

    python(abi) RPM DEB Download python(abi) RPM DEB Download

  5. Invalid embedded descriptor for ".proto".Dependencies passed (Protobufer)解决办法

    前言 之前开发的时候,发现居然出现了Dependencies passed to FileDescriptor.buildFrom() don't match those listed in the ...

  6. php 多进程中的信号问题

    1.以下代码sleep时间远小于20 <?php // 当子进程退出时,会触发该函数 function sig_handler($sig) { switch($sig) { case SIGCH ...

  7. wx_sample.php

    <?php /**   * wechat php test   */ //define your token define("TOKEN", "weixin&quo ...

  8. Hadoop Spark 集群简便安装总结

    本人实际安装经验,目的是为以后高速安装.仅供自己參考. 一.Hadoop 1.操作系统一如既往:①setup关掉防火墙.②vi /etc/sysconfig/selinux,改SELINUX=disa ...

  9. SlidingMenu开源项目滑动界面的实现总结

    先上图 须要准备的是先得在GitHub上下载ActionBarSherlock-master.zip,和SlidingMenu-master.zip这两个开源文件,然后解压这两个包,SlidingMe ...

  10. 【LaTeX排版】LaTeX论文排版&lt;三&gt;

    A picture is worth a thousand words(一图胜千言).图在论文中的重要性不言而喻,本文主要解说图的制作与插入. 1.图像的插入     图像能够分为两大类:位图和向量图 ...