Fire Net HDU
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
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
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
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的更多相关文章
- (匹配)Fire Net --hdu --1045
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- Fire Net HDU 1045
简单深搜,可以完全暴力,不会超时的. #include<iostream> #include<cstring> #include<cmath> using name ...
- A - Fire Net - hdu 1045(二分图匹配)
题意:一个阵地可以向四周扫射,求出来最多能修多少个阵地,墙不可以被扫射透,阵地不能同行或者或者列(有墙隔着例外) 分析:很久以前就做过这道题..当时是练习深搜来着,不过时间复杂度比较高,现在再看突然发 ...
- Fire Net HDU - 1045(二分匹配)
把每一列中相邻的 . 缩为一个点 作为二分图的左边 把每一行中相邻的 . 缩为一个点 作为二分图的右边 然后求最大匹配即可 这题用匈牙利足够了...然而..我用了hk...有点大材小用的感觉// ...
- Fire Net HDU - 1045 (二分图匹配)
题意: 给出一张图,图中'X'表示wall,'.'表示空地,可以放置blockhouse同一条直线上只能有一个blockhouse,除非有wall 隔开,问在给出的图中最多能放置多少个blockhou ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
- [kuangbin带你飞]专题1-23题目清单总结
[kuangbin带你飞]专题1-23 专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 Fli ...
- ACM--[kuangbin带你飞]--专题1-23
专题一 简单搜索 POJ 1321 棋盘问题POJ 2251 Dungeon MasterPOJ 3278 Catch That CowPOJ 3279 FliptilePOJ 1426 Find T ...
- hdu 1045 Fire Net(最小覆盖点+构图(缩点))
http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS Memory Limit:32768KB ...
随机推荐
- 上Https 和 http 差分
HTTPS 和 HTTP 差协议 超文本传输协定HTTP 对于web 浏览器和现场服务之间传递消息,HTTP 以纯文本协议 发送内容 无论不提供数据加密方法 假设拦截攻击web 浏览器和网站serve ...
- Java创建、重命名、删除文件和文件夹(转)
Java的文件操作太基础,缺乏很多实用工具,比如对目录的操作,支持就非常的差了.如果你经常用Java操作文件或文件夹,你会觉得反复编写这些代码是令人沮丧的问题,而且要大量用到递归. 下面是的一个解决方 ...
- oracle 通过查询灵活插入数据 insert into ...select..
insert into reg_user (id,name,password,area_code,reg_time,first_pswd,record_type) select l.reg_user_ ...
- 基于Cocos2dx开发卡牌游戏Demo_放开那三国 2.0
PS:下载地址在最以下 1.登录 2.副本选择 3.地图 4. 选择敌人 5. 战斗 6. 战斗结算 7. 地图拓展 8. 武将拓展 9. 下载地址: 点击打开链接
- Linux 系统文件夹结构
登录后,在当前的命令窗口中输入命令: <span style="font-size:14px;">ls /</span> 你的终端上会出现例如以下的代码: ...
- VLine2.0——仿阿里巴巴VIPABC真人视频在线教育(基于Flash支持一对多多对多Web在线视频)
感兴趣的朋友可与我联系:acsebt@qq.com 一.登陆页 二.功能页
- 在Windows下使用Hexo+GithubPage搭建博客的过程
1.安装Node.js 下载地址:传送门 去 node.js 官网下载相应版本,进行安装即可. 可以通过node -v的命令来测试NodeJS是否安装成功 2.安装Git 下载地址:传送门 去 Git ...
- Eclipse设置的断点失效的解决办法
使用Eclipse的同胞们,如果你哪天惊奇的发现调试时,明明设置了断点,按道理就是要执行设置断点的那条语句的,可是偏偏Eclipse视你设置的断点不见,不要害怕,不要恐慌,这样的问题不应该导致偶们疯狂 ...
- Netflix公司监控内部安全的开源项目
Netfix公司已经公布了三个内部工具,用于捕捉黑客在使用互联网服务时留下的痕迹. AndyHoernecke和Netflix公司的云安全团队成员ScottBehrens指出:"很多安全团队 ...
- linux系统启动过程的列表
linux系统启动过程的列表 载入BIOS的硬件信息并进行自检.然后根据设置取得第一个可启动的设备: 读取并运行第一个启动设备内MBR(master boot record,主引导分区)的boot l ...