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. LCS最大公共子序列问题

    在生物应用中,经常需要比较两个(或多个)不同生物体的DNA, 例如:某种生物的DNA可能为S1=ACCGGTCGAGTGCGCGGAAGCCGGCCGAA, 另一种生物的DNA可能为S2=GTCGTT ...

  2. 2014辽宁省赛 Repeat Number

    问题 C: Repeat Number 时间限制: 1 Sec  内存限制: 128 MB [cid=1073&pid=2&langmask=0">提交][状态][论坛 ...

  3. Linux lamp环境编译安装

    1.安装准备: 1)httpd-2.0.52.tar.gz 2)mysql-4.1.12.tar.gz 3)libxml2-2.6.27.tar 4)freetype-2.1.10.tar 5)gd- ...

  4. 用Java写个ftp传输类实现文件的上传和下载,用ikvmc转成dll

    1.Java类: package com.wjy.ftp.transmission; import java.io.File; import java.io.FileOutputStream; imp ...

  5. 让你提前认识软件开发(35):怎样改动SQL脚本以完毕需求?

    第2部分 数据库SQL语言 怎样改动SQL脚本以完毕需求? SQL脚本的改动和C语言代码的改动流程是一样的,都要遵循下面步骤:         第一步,阅读需求.弄清楚自己要完毕什么功能.       ...

  6. 怎样在C++中获得完整的类型名称

    Wrote by mutouyun. (http://darkc.at/cxx-get-the-name-of-the-given-type/) 地球人都知道C++里有一个typeid操作符能够用来获 ...

  7. 《JavaScript设计模式与开发实践》读书笔记之享元模式

    1. 享元模式 享元模式是一种用于性能优化的模式,享元模式的核心是运用共享技术来有效支持大量细粒度的对象 1.1 传统的文件上传方法 以文件上传为例,文件上传功能可以选择依照队列,一个一个的排队上传, ...

  8. git笔记之解决eclipse不能提交jar等文件的问题

    今天用git托管了一个java web项目,由于是web项目,所以要上传jar文件(此项目未使用maven管理),一直使用git commit and push,就是在server上看不到jar文件上 ...

  9. Android在Context详细解释 ---- 你不知道Context

                                                                                                         ...

  10. poj 3101 Astronomy(分数的最小公倍数)

    http://poj.org/problem? id=3101 大致题意:求n个运动周期不全然同样的天体在一条直线上的周期. 这题我是看解题报告写的,没想到选用參照物,用到了物理中的角速度什么的. 由 ...