hdu 4770 Lights Against Dudely

news/2024/10/22 16:22:15/

用离中心距离为1的L去覆盖最多十五个点,#不能被覆盖,可以覆盖的地方可以越界,有一个L可以是旋转0,90,180,270去覆盖的

问,最少要多少个L可以实现全覆盖。

枚举可旋转的L所在的位置,然后直接爆搜……

没想到直接A了……

数据比较弱么……

#include<iostream>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int n,row,line,goal,all;
bool islight[210][210];
bool iscan[210][210];
bool used[25];
int dx[4][2];
int dy[4][2];
void make()
{dx[0][0]=-1;dx[0][1]=0;dx[1][0]=0;dx[1][1]=1;dy[0][0]=0;dy[0][1]=1;dy[1][0]=1;dy[1][1]=0;dx[2][0]=1;dx[2][1]=0;dx[3][0]=0;dx[3][1]=-1;dy[2][0]=0;dy[2][1]=-1;dy[3][0]=-1;dy[3][1]=0;
}
struct node
{int x,y;node(){}node(int a,int b){x=a;y=b;}
}a[25];
bool dfs(int s,int cnt,int step)
{int i,t;bool flag,flag1,flag2,flag3;if(step==goal)return cnt==all;for(i=s;i<n;i++){if(used[i])continue;t=cnt;flag1=flag2=flag3=0;if(a[i].x>0){if(!iscan[a[i].x-1][a[i].y])continue;if(!islight[a[i].x-1][a[i].y]){t++;islight[a[i].x-1][a[i].y]=1;flag1=1;}}if(a[i].y<line-1){if(!iscan[a[i].x][a[i].y+1])continue;if(!islight[a[i].x][a[i].y+1]){t++;islight[a[i].x][a[i].y+1]=1;flag2=1;}}if(!islight[a[i].x][a[i].y]){t++;islight[a[i].x][a[i].y]=1;flag3=1;}flag=dfs(i+1,t,step+1);if(flag1)islight[a[i].x-1][a[i].y]=0;if(flag2)islight[a[i].x][a[i].y+1]=0;if(flag3)islight[a[i].x][a[i].y]=0;if(flag)return 1;}return 0;
}
bool isbeyond(int x,int y)
{return x<0||y<0||x>=row||y>=line;
}
int main()
{string s;int i,j,k,cnt,ans;make();while(cin>>row>>line){if(row==0&&line==0)break;n=all=0;memset(iscan,0,sizeof(iscan));for(i=0;i<row;i++){cin>>s;for(j=0;j<line;j++){if(s[j]=='.'){a[n++]=node(i,j);iscan[i][j]=1;all++;}}}ans=16;for(i=0;i<n;i++){for(j=0;j<4;j++){cnt=1;memset(islight,0,sizeof(islight));for(k=0;k<2;k++){if(isbeyond(a[i].x+dx[j][k],a[i].y+dy[j][k]))continue;if(!iscan[a[i].x+dx[j][k]][a[i].y+dy[j][k]])break;islight[a[i].x+dx[j][k]][a[i].y+dy[j][k]]=1;cnt++;}if(k<2)continue;islight[a[i].x][a[i].y]=1;for(goal=1;goal<=n;goal++){if(dfs(0,cnt,1)){ans=min(ans,goal);break;}}}}if(n==0)ans=0;else if(ans==16)ans=-1;cout<<ans<<endl;}return 0;
}

Lights Against Dudely

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1938    Accepted Submission(s): 570


Problem Description
Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money."
Hagrid: "Well there's your money, Harry! Gringotts, the wizard bank! Ain't no safer place. Not one. Except perhaps Hogwarts."
— Rubeus Hagrid to Harry Potter.
  Gringotts Wizarding Bank is the only bank of the wizarding world, and is owned and operated by goblins. It was created by a goblin called Gringott. Its main offices are located in the North Side of Diagon Alley in London, England. In addition to storing money and valuables for wizards and witches, one can go there to exchange Muggle money for wizarding money. The currency exchanged by Muggles is later returned to circulation in the Muggle world by goblins. According to Rubeus Hagrid, other than Hogwarts School of Witchcraft and Wizardry, Gringotts is the safest place in the wizarding world.
  The text above is quoted from Harry Potter Wiki. But now Gringotts Wizarding Bank is not safe anymore. The stupid Dudley, Harry Potter's cousin, just robbed the bank. Of course, uncle Vernon, the drill seller, is behind the curtain because he has the most advanced drills in the world. Dudley drove an invisible and soundless drilling machine into the bank, and stole all Harry Potter's wizarding money and Muggle money. Dumbledore couldn't stand with it. He ordered to put some magic lights in the bank rooms to detect Dudley's drilling machine. The bank can be considered as a N × M grid consisting of N × M rooms. Each room has a coordinate. The coordinates of the upper-left room is (1,1) , the down-right room is (N,M) and the room below the upper-left room is (2,1)..... A 3×4 bank grid is shown below:

  Some rooms are indestructible and some rooms are vulnerable. Dudely's machine can only pass the vulnerable rooms. So lights must be put to light up all vulnerable rooms. There are at most fifteen vulnerable rooms in the bank. You can at most put one light in one room. The light of the lights can penetrate the walls. If you put a light in room (x,y), it lights up three rooms: room (x,y), room (x-1,y) and room (x,y+1). Dumbledore has only one special light whose lighting direction can be turned by 0 degree,90 degrees, 180 degrees or 270 degrees. For example, if the special light is put in room (x,y) and its lighting direction is turned by 90 degrees, it will light up room (x,y), room (x,y+1 ) and room (x+1,y). Now please help Dumbledore to figure out at least how many lights he has to use to light up all vulnerable rooms.
  Please pay attention that you can't light up any indestructible rooms, because the goblins there hate light.


Input
There are several test cases.
  In each test case:
  The first line are two integers N and M, meaning that the bank is a N × M grid(0<N,M <= 200).
  Then a N×M matrix follows. Each element is a letter standing for a room. '#' means a indestructible room, and '.' means a vulnerable room.
  The input ends with N = 0 and M = 0

Output
For each test case, print the minimum number of lights which Dumbledore needs to put.
  If there are no vulnerable rooms, print 0.
  If Dumbledore has no way to light up all vulnerable rooms, print -1.

Sample Input
  
2 2 ## ## 2 3 #.. ..# 3 3 ### #.# ### 0 0

Sample Output
  
0 2 -1

Source
2013 Asia Hangzhou Regional Contest


http://www.ppmy.cn/news/147416.html

相关文章

HDU 4770 DFS状压

一个n*m的房间有的房间是可破坏的&#xff0c;其他不可破坏&#xff0c;现在给你一些L型的灯&#xff0c;其中只有一个可以旋转&#xff0c;其他不能&#xff0c;让你用最少的灯覆盖所有的可破坏区域&#xff0c;且不能覆盖不可破坏的区域。 枚举旋转的灯&#xff0c;对剩下的…

杭电4770

这道题有几个陷阱&#xff1a; 1.灯光可以找到房间以外 2.只有一个可以旋转的灯 3.最多有十五个需要灯光的房间 4.一个房间最多只能有一盏灯 3 3 #.# . . . #.# 这组数据上错了好久。。。 大致解题思路&#xff1a; 记录下来需要灯光的发房间数&#xff0c;对其进行遍历&a…

Core i7-4770K的详细性能

新品发布前总能看到一些规格、性能方面的偷跑&#xff0c;但大多都是零零碎碎的&#xff0c;关键时刻还得看权威大站。Toms Hardware今天放出猛料&#xff0c;公布了Intel Haswell处理器家族旗舰型号Core i7-4770K的详细性能&#xff0c;基本可以对下代平台有个整体的印像了。 …

P4770 [NOI2018]你的名字

蒟蒻表示不会sam凉凉了&#xff0c;所以只能提高SA技巧&#xff1f; 题意&#xff1a;有一个串\(A\)&#xff0c;每次选择一个\(A\)的子串\(A\)&#xff0c;以及串\(B\)&#xff0c;问\(B\)的所有本质不同子串中不在\(A\)中的串的数量。 &#xff08;定义\(A_i\)表示以字符\(A_…

hdu4770 状态压缩+枚举

http://acm.hdu.edu.cn/showproblem.php?pid4770 Problem Description Harry: "But Hagrid. How am I going to pay for all of this? I havent any money." Hagrid: "Well theres your money, Harry! Gringotts, the wizard bank! Aint no safer place. Not…

BZOJ4770: 图样 (随机点值求异或最小生成树边权和)

题目描述&#xff1a; n ≤ 50 , m ≤ 8 n\le50,m\le8 n≤50,m≤8 题目分析&#xff1a; 根据最小生成树有小到大加入边可以将点按照二进制最高位分组&#xff0c;统计所有情况的边权和。 Code&#xff1a; #include<bits/stdc.h> #define maxn 55 #define maxm 9 u…

【JZOJ4770】闭门造车

Description 自从htn体验了一把飙车的快感&#xff0c;他就下定决心要闭门造车&#xff01;但是他两手空空怎么造得出车来呢?无奈的他只好来到了汽车零部件商店。 一走进商店&#xff0c;玲琅满目的各式零件看得htn眼花缭乱。但是他很快便反应过来:我只要买一套好的零件就行…

chmod 4770的第一位解释

权限标志通过三个“位”来定义&#xff0c;分别是&#xff1a; setuid&#xff1a;设置使文件在执行阶段具有文件所有者的权限。比如/usr/bin/passwd&#xff0c;如果一般用户执行该文件&#xff0c;则在执行过程中&#xff0c;该文件可以获得root权限&#xff0c;从而可以更改…