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 ...
随机推荐
- 黑马程序员:Java基础总结----类加载器
黑马程序员:Java基础总结 类加载器 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 类加载器 Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个 ...
- Java NIO的性能
最近调研了一下mina和netty框架的性能,主要是想了解java nio在单机能支持多少长连接. 首先,mina的qq群有同学反映说单机支持3w长连接是没问题的 其次,http://amix.dk/ ...
- Android中G-Sensor相关流程
1.使G-sensor正常工作需要做的事: G-sensor driver文件包括: driver/i2c/chips/lis331dl.c driver/i2c/chips/sensorioctl. ...
- 使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)——初识WiX
原文:使用WiX Toolset创建.NET程序发布Bootstrapper(安装策略管理)(一)--初识WiX Visual Studio 打包安装七宗罪 开发.NET的人,肯定会使用Visual ...
- ReentrantLock可重入锁的使用场景(转)
摘要 从使用场景的角度出发来介绍对ReentrantLock的使用,相对来说容易理解一些. 场景1:如果发现该操作已经在执行中则不再执行(有状态执行) a.用在定时任务时,如果任务执行时间可能超过下次 ...
- Remote Desktop Organizer – 管理组织远程桌面 - 小众软件
http://www.appinn.com/remote-desktop-organizer/
- Exception in thread "http-apr-8080-exec-6" java.lang.OutOfMemoryError: PermGen space 解决!
Exception in thread "http-apr-8080-exec-6" java.lang.OutOfMemoryError: PermGen space at ja ...
- [poj 1127]Jack Straws[线段相交][并查集]
题意: 给出一系列线段,判断某两个线段是否连通. 思路: 根据线段相交情况建立并查集, 在同一并查集中则连通. (第一反应是强连通分量...实际上只要判断共存即可, 具体的方向啊是没有关系的..) 并 ...
- tera term 残ALT债券
Setup -> Keyboard对话框 Meta key变: left 版权声明:本文博客原创文章,博客,未经同意,不得转载.
- windows server 2012显示桌面图标
windows server 2012安装后是没有桌面图标的,可以通过下面方式显示出来: 打开powershell rundll32.exe shell32.dll,Control_RunDLL de ...