Hdu - 1045 - Fire Net
2013-07-20 22:24
495 查看
上题目:
Total Submission(s): 4734 Accepted Submission(s): 2684
[align=left]Problem Description[/align]
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.
1045
Fire Net
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4734 Accepted Submission(s): 2684
[align=left]Problem Description[/align]
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.
#include <stdio.h> #include <string.h> #define MAX 10 using namespace std; int s[MAX][MAX],max; bool jadge2(int n) { int i,j,a; for(i=1;i<=n;i++) { a=0; for(j=1;j<=n;j++) { if(s[i][j]==1) { a++; if(a>1) return 0; } else if(s[i][j]==-1) a=0; } } for(j=1;j<=n;j++) { a=0; for(i=1;i<=n;i++) { if(s[i][j]==1) { a++; if(a>1) return 0; } else if(s[i][j]==-1) a=0; } } return 1; } void jadge(int n,int count) { int i,j; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(s[i][j]) continue; s[i][j]=1; if(jadge2(n)) { max=count+1 > max ? count+1 : max; jadge(n,count+1); } s[i][j]=0; } } } int main() { int n,i,j; char c,o; //freopen("data.txt","r",stdin); while(scanf("%d",&n),n) { scanf("%c",&o); memset(s,-1,sizeof(s)); for(i=1;i<=n;i++) { j=1; while((c=getchar()),(c=='.' || c=='X')) { if(c=='.') s[i][j]=0; else s[i][j]=-1; j++; } } /* for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { printf("%d",s[i][j]); } printf("\n"); } */ max=0; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { jadge(n,0); } } printf("%d\n",max); } return 0; }
1045
相关文章推荐
- HDU 1045-Fire Net
- HDU 1045 Fire Net【DFS深搜】
- HDU 1045 Fire Net
- HDU1045:Fire Net(DFS)
- HDU 1045.Fire Net【DFS暴力搜索】【3月15】
- hdu 1045 Fire Net
- hdu 1045 Fire Net
- hdu 1045 Fire Net
- hdu 1045 Fire Net
- 杭电hdu 1045 Fire Net dfs
- hdu 1045 Fire Net
- HDU 1045 Fire Net
- HDU 1045 Fire Net
- hdu1045 Fire Net
- HDU 1045 Fire Net
- hdu 1045 Fire Net 二分行列匹配
- HDU_1045 Fire Net
- HDU 1045 - Fire Net
- HDU1045 Fire Net
- hdu 1045 Fire Net&二分图解法