Fire Net HDU 1045

简单深搜,可以完全暴力,不会超时的。


#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define MAX(a,b) (a>b?a:b)
char maze[10][10];
int n, maxn;

void DFS(int step,int count);
int cheak(int x, int y);
int main()
{
int i;
while(scanf("%d",&n), n)
{
maxn = 0;
for(i = 0; i < n; i++)
scanf("%s",maze[i]);
DFS(0,0);
printf("%d\n",maxn);
}
return 0;
}

void DFS(int step,int count)
{
int x, y;
maxn = MAX(maxn,count);
if(step == n*n)
return ;
x = step/n;
y = step%n;
if(maze[x][y] == ‘.‘ && cheak(x,y))
{
maze[x][y] = ‘O‘;
DFS(step+1,count+1);
maze[x][y] = ‘.‘;
}
DFS(step + 1, count);
}

int cheak(int x, int y)
{
int i;
for(i = x-1; i >= 0; i--)
{
if(maze[i][y] == ‘O‘)
return 0;
else if(maze[i][y] == ‘X‘)
break;
}
for(i = y-1; i >= 0; i--)
{
if(maze[x][i] == ‘O‘)
return 0;
else if(maze[x][i] == ‘X‘)
break;
}
return 1;
}

Fire Net HDU 1045,布布扣,bubuko.com

时间: 2024-10-13 10:23:49

Fire Net HDU 1045的相关文章

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

链接: http://acm.hdu.edu.cn/showproblem.php?pid=1045 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82834#problem/A 一看原题,先用搜索写一下,还是要学学匹配吧! 以前的代码: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> us

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

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

Fire Net HDU - 1045(二分匹配)

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

HDU 1045 - Fire Net (最大独立集)

题意:给你一个正方形棋盘.每个棋子可以直线攻击,除非隔着石头.现在要求所有棋子都不互相攻击,问最多可以放多少个棋子. 这个题可以用搜索来做.每个棋子考虑放与不放两种情况,然后再判断是否能互相攻击来剪枝.最后取可以放置的最大值. 这里我转化成求最大独立集来做. 首先将每个空地编号,对于每个空地,与该位置可以攻击到的空地连边.找最多的空地使得不互相攻击,即求该图的最大独立集.与搜索做法基本一致,但是说法略有不同. 1 #include<iostream> 2 #include<cstring

HDU 1045——Fire Net——————【最大匹配、构图、邻接矩阵做法】

Fire Net Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1045 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, e

HDU 1045 Fire Net 贪心

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 wh

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

http://acm.hdu.edu.cn/showproblem.php?pid=1045 Fire Net Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1045 Description Suppose that we have a square city with straight streets. A map of a city

Hdu 1045 二分匹配

题目链接 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6282    Accepted Submission(s): 3551 Problem Description Suppose that we have a square city with straight streets. A map of a city i

HDU 1045 DFS暴搜

Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6229    Accepted Submission(s): 3506 Problem Description Suppose that we have a square city with straight streets. A map of a city is a s