这题说的是一在一个N*M的房间内,然后有些房间不能被灯光照亮,有一个灯可以转动方向,其他的灯只能在固定一个方向上,因为数据比较小,所以比较水,直接暴力的进行枚举就好了,但是还是 wa了很久,原因没认真读题,然后就是小细节的错误,在标记的时候背后面的,点给覆盖了,(考虑不周全)。

#include <iostream>
#include<string.h>
#include<cstdio>
using namespace std;
const int MAXX=1000000;
struct point
{
int x,y;
point (int a=0,int b=0){x=a;y=b;}
};
bool operator ==(const point &a,const point &b)
{
return a.x==b.x&&a.y==b.y;
}
point operator +(point a,point b){ return point(a.x+b.x,a.y+b.y);}
char map[205][205];
int mark[205][205];
point p3[4][2]=
{
{point(0,-1),point(-1,0)},{point(-1,0),point(0,1)},
{point(0,1),point(1,0)},{point(1,0),point(0,-1)}
};
point p1[8][2]=
{ {point(0,-1),point(1,-1)},{point(0,-1),point(-1,-1)},
{point(-1,0),point(-1,-1)},{point(-1,0),point(-1,1)},
{point(0,1),point(-1,1)},{point(0,1),point(1,1)},
{point(1,0),point(1,1)},{point(1,0),point(1,-1)}
};
point aboutt[20],mayt[20],hoct[20],bet[20];
int n,m,LENa,LENm,LENc,MINlen,mayLEN,LENb;
bool work1()
{
int i;
point B=hoct[0],temp1,temp2;
for(i=0;i<4;i++)
{
temp1=B+p3[i][0];
temp2=B+p3[i][1];
if(map[temp1.x][temp1.y]==0&&map[temp2.x][temp2.y]==0)
return true;
}
for(i=0;i<8;i++)
{ temp1=B+p1[i][0];
temp2=B+p1[i][1];
if(map[temp1.x][temp1.y]==0&&mark[temp1.x][temp1.y]!=2&&map[temp2.x][temp2.y]==0&&temp1.x<=n&&temp1.y<=m)
return true;
}
return false;
}
bool work2()
{
point temp1,temp2;
point A=hoct[0],B=hoct[1];
for(int i =0;i<8;i++)
{
temp1=A+p1[i][0];
temp2=A+p1[i][1];
if(temp1==B&&map[temp2.x][temp2.y]==0) return true;
if(temp2==B&&map[temp1.x][temp1.y]==0&&mark[temp1.x][temp1.y]!=2&&temp1.x<=n&&temp1.y<=m)
return true;
}
return false;
}
bool work3()
{
int i;
point A=hoct[0],B=hoct[1],C=hoct[2],temp1,temp2;
for( i=0;i<4;i++)
{
temp1=A+p3[i][0];
temp2=A+p3[i][1];
if(temp1==B&&temp2==C) return true;
if(temp2==B&&temp1==C) return true;
}
for( i=0;i<4;i++)
{
temp1=B+p3[i][0];
temp2=B+p3[i][1];
if(temp1==A&&temp2==C) return true;
if(temp2==A&&temp1==C) return true;
}
for( i=0;i<4;i++)
{
temp1=C+p3[i][0];
temp2=C+p3[i][1];
if(temp1==B&&temp2==A) return true;
if(temp2==B&&temp1==A) return true;
}
return false;
}
bool print_subet(int s)
{
int i;
LENb=0;
memset(mark,0,sizeof(mark));
for( i=0;i<LENm;i++)
if(s&(1<<i)) {
bet[LENb++]=mayt[i];
mark[mayt[i].x][mayt[i].y]=2;
if(mark[mayt[i].x][mayt[i].y+1]!=2)
mark[mayt[i].x][mayt[i].y+1]=1;
if(mark[mayt[i].x-1][mayt[i].y]!=2)
mark[mayt[i].x-1][mayt[i].y]=1;
}
LENc=0;
for( i=0;i<LENa;i++)
if(mark[aboutt[i].x][aboutt[i].y]==0)
hoct[LENc++]=aboutt[i];
if(LENc>3) return false;
if(LENc==0) { mayLEN=LENb; return true; }
if(LENc==1) { if(work1()){mayLEN=LENb+1;return true;}}
if(LENc==2) { if(work2()){mayLEN=LENb+1;return true;}}
if(LENc==3) { if(work3()){mayLEN=LENb+1;return true;}}
return false;
}
int main()
{
int i,j;
while(scanf("%d%d",&n,&m)==2)
{
if((n+m)==0) break;
mayLEN=MINlen=MAXX;
LENa=LENm=0;
memset(map,0,sizeof(map));
for( i=1;i<=n;i++)
{
scanf("%s",map[i]+1);
for( j=1;j<=m;j++)
{
if(map[i][j]=='.')
{
map[i][j]=0;
aboutt[LENa++]=point(i,j);
}
}
}
for( i=0;i<LENa;i++)
if(map[aboutt[i].x][aboutt[i].y+1]==0&&map[aboutt[i].x-1][aboutt[i].y]==0)
mayt[LENm++]=aboutt[i];
for( i=0;i<(1<<LENm);i++)
if(print_subet(i))
{
if(MINlen>mayLEN)
MINlen=mayLEN;
} if(MINlen==MAXX) puts("-1");
else printf("%d\n",MINlen);
} return 0;
}

HDU 4770的更多相关文章

  1. hdu 4770 Lights Against Dudely(回溯)

    pid=4770" target="_blank" style="">题目链接:hdu 4770 Lights Against Dudely 题 ...

  2. hdu 4770(枚举 + dfs爆搜)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4770 思路:由于最多只有15个".",可以直接枚举放置的位置,然后判断是否能够全部 ...

  3. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  4. HDU 4770 Lights Against DudelyLights

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  5. HDU 4770 Lights Against Dudely

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  6. HDU 4770 Lights Against Dudely(暴力+状压)

    思路: 这个题完全就是暴力的,就是代码长了一点. 用到了状压,因为之前不知道状压是个东西,大佬们天天说,可是我又没学过,所以对状压有一点阴影,不过这题中的状压还是蛮简单的. 枚举所有情况,取开灯数最少 ...

  7. HDU 4770 Lights Against Dudely (2013杭州赛区1001题,暴力枚举)

    Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  8. hdu 4770 13 杭州 现场 A - Lights Against Dudely 暴力 bfs 状态压缩DP 难度:1

    Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money.&quo ...

  9. hdu 4770 状压+枚举

    /* 长记性了,以后对大数组初始化要注意了!140ms 原来是对vis数组进行每次初始化,每次初始化要200*200的复杂度 一直超时,发现没必要这样,直接标记点就行了,只需要一个15的数组用来标记, ...

随机推荐

  1. Memcached存Session数据、访问安全性、使用场景总结(3)

    最近做了一个单点登录SSO,登陆后的凭证放到Memcached令牌放到Cookies:但是用户经常掉线,开发环境和测试却没有这个问题,最后从Memcached找到原因. Memcached概念.作用. ...

  2. 自动释放池autoreleasepool

    自动释放池是NSAutoreleasePool的实例,其中包含了收到autorelease消息的对象.当一个自动释放池自身被销毁(dealloc)时,它会给池中每一个对象发送一个release消息(如 ...

  3. geotrellis使用(三十二)大量GeoTiff文件实时发布TMS服务

    前言 在上一篇文章中我讲了如何直接将Geotiff文件发布为TMS服务,在其中只讲了单幅Geotiff的操作,其实单幅这种量级的数据对Geotrellis来说就是杀鸡焉用牛刀,Geotrellis针对 ...

  4. thinkCMF----增删改查操作

    thinkCMF的增删改查基本操作: 一.增加数据 $res = Db::name('form')->insert($data); 示例代码: public function index(){ ...

  5. jeb 下载

    jeb-1.5.201408040(full)_keygen_by_scz(20150725) http://scz.617.cn/ 修改jeb_wincon.bat 中java home 变量,然后 ...

  6. Rhino

    http://shrinksafe.dojotoolkit.org/ a JavaScript interpreter

  7. 青蛙的约会---poj1061(扩展欧几里德)

    题目链接:http://poj.org/problem?id=1061 就是找到满足 (X+mt)-(Y+nt) = Lk 的 t 和 k 即可 上式可化简为 (n-m)t + Lk = X-Y;满足 ...

  8. lua 获取指定目录下指定后缀文件名

    lfs库是很好的选择,可惜不会编译,无奈只能自己写个简单的lua库.代码如下: #include <io.h> #include <stdio.h> #include &quo ...

  9. 【python-opencv】18-图像梯度+图像边界

    效果图: *一阶导数与Soble算子 *二阶导数与拉普拉斯算子 定义:把图片想象成连续函数,因为边缘部分的像素值是与旁边像素明显有区别的,所以对图片局部求极值,就可以得到整幅图片的边缘信息了. 不过图 ...

  10. npm设置淘宝镜像

    npm config set registry https://registry.npm.taobao.org --global npm config set disturl https://npm. ...