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

  1. #include <iostream>
  2. #include<string.h>
  3. #include<cstdio>
  4. using namespace std;
  5. const int MAXX=1000000;
  6. struct point
  7. {
  8. int x,y;
  9. point (int a=0,int b=0){x=a;y=b;}
  10. };
  11. bool operator ==(const point &a,const point &b)
  12. {
  13. return a.x==b.x&&a.y==b.y;
  14. }
  15. point operator +(point a,point b){ return point(a.x+b.x,a.y+b.y);}
  16. char map[205][205];
  17. int mark[205][205];
  18. point p3[4][2]=
  19. {
  20. {point(0,-1),point(-1,0)},{point(-1,0),point(0,1)},
  21. {point(0,1),point(1,0)},{point(1,0),point(0,-1)}
  22. };
  23. point p1[8][2]=
  24. { {point(0,-1),point(1,-1)},{point(0,-1),point(-1,-1)},
  25. {point(-1,0),point(-1,-1)},{point(-1,0),point(-1,1)},
  26. {point(0,1),point(-1,1)},{point(0,1),point(1,1)},
  27. {point(1,0),point(1,1)},{point(1,0),point(1,-1)}
  28. };
  29. point aboutt[20],mayt[20],hoct[20],bet[20];
  30. int n,m,LENa,LENm,LENc,MINlen,mayLEN,LENb;
  31. bool work1()
  32. {
  33. int i;
  34. point B=hoct[0],temp1,temp2;
  35. for(i=0;i<4;i++)
  36. {
  37. temp1=B+p3[i][0];
  38. temp2=B+p3[i][1];
  39. if(map[temp1.x][temp1.y]==0&&map[temp2.x][temp2.y]==0)
  40. return true;
  41. }
  42. for(i=0;i<8;i++)
  43. {
  44.  
  45. temp1=B+p1[i][0];
  46. temp2=B+p1[i][1];
  47. 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)
  48. return true;
  49. }
  50. return false;
  51. }
  52. bool work2()
  53. {
  54. point temp1,temp2;
  55. point A=hoct[0],B=hoct[1];
  56. for(int i =0;i<8;i++)
  57. {
  58. temp1=A+p1[i][0];
  59. temp2=A+p1[i][1];
  60. if(temp1==B&&map[temp2.x][temp2.y]==0) return true;
  61. if(temp2==B&&map[temp1.x][temp1.y]==0&&mark[temp1.x][temp1.y]!=2&&temp1.x<=n&&temp1.y<=m)
  62. return true;
  63. }
  64. return false;
  65. }
  66. bool work3()
  67. {
  68. int i;
  69. point A=hoct[0],B=hoct[1],C=hoct[2],temp1,temp2;
  70. for( i=0;i<4;i++)
  71. {
  72. temp1=A+p3[i][0];
  73. temp2=A+p3[i][1];
  74. if(temp1==B&&temp2==C) return true;
  75. if(temp2==B&&temp1==C) return true;
  76. }
  77. for( i=0;i<4;i++)
  78. {
  79. temp1=B+p3[i][0];
  80. temp2=B+p3[i][1];
  81. if(temp1==A&&temp2==C) return true;
  82. if(temp2==A&&temp1==C) return true;
  83. }
  84. for( i=0;i<4;i++)
  85. {
  86. temp1=C+p3[i][0];
  87. temp2=C+p3[i][1];
  88. if(temp1==B&&temp2==A) return true;
  89. if(temp2==B&&temp1==A) return true;
  90. }
  91. return false;
  92. }
  93. bool print_subet(int s)
  94. {
  95. int i;
  96. LENb=0;
  97. memset(mark,0,sizeof(mark));
  98. for( i=0;i<LENm;i++)
  99. if(s&(1<<i)) {
  100. bet[LENb++]=mayt[i];
  101. mark[mayt[i].x][mayt[i].y]=2;
  102. if(mark[mayt[i].x][mayt[i].y+1]!=2)
  103. mark[mayt[i].x][mayt[i].y+1]=1;
  104. if(mark[mayt[i].x-1][mayt[i].y]!=2)
  105. mark[mayt[i].x-1][mayt[i].y]=1;
  106. }
  107. LENc=0;
  108. for( i=0;i<LENa;i++)
  109. if(mark[aboutt[i].x][aboutt[i].y]==0)
  110. hoct[LENc++]=aboutt[i];
  111. if(LENc>3) return false;
  112. if(LENc==0) { mayLEN=LENb; return true; }
  113. if(LENc==1) { if(work1()){mayLEN=LENb+1;return true;}}
  114. if(LENc==2) { if(work2()){mayLEN=LENb+1;return true;}}
  115. if(LENc==3) { if(work3()){mayLEN=LENb+1;return true;}}
  116. return false;
  117. }
  118. int main()
  119. {
  120. int i,j;
  121. while(scanf("%d%d",&n,&m)==2)
  122. {
  123. if((n+m)==0) break;
  124. mayLEN=MINlen=MAXX;
  125. LENa=LENm=0;
  126. memset(map,0,sizeof(map));
  127. for( i=1;i<=n;i++)
  128. {
  129. scanf("%s",map[i]+1);
  130. for( j=1;j<=m;j++)
  131. {
  132. if(map[i][j]=='.')
  133. {
  134. map[i][j]=0;
  135. aboutt[LENa++]=point(i,j);
  136. }
  137. }
  138. }
  139. for( i=0;i<LENa;i++)
  140. if(map[aboutt[i].x][aboutt[i].y+1]==0&&map[aboutt[i].x-1][aboutt[i].y]==0)
  141. mayt[LENm++]=aboutt[i];
  142. for( i=0;i<(1<<LENm);i++)
  143. if(print_subet(i))
  144. {
  145. if(MINlen>mayLEN)
  146. MINlen=mayLEN;
  147. }
  148.  
  149. if(MINlen==MAXX) puts("-1");
  150. else printf("%d\n",MINlen);
  151. }
  152.  
  153. return 0;
  154. }

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. Laya 图集动画

    参考: 图集动画运用 一.准备素材 从爱给网找到几个素材 二.使用Laya的图集工具 菜单栏选择工具->图集打包工具,然后选择序列图所在的文件夹 生成了个.rec...说好的.atlas呢... ...

  2. Android控件开发——ListView

    上篇博客解决了Android客户端通过WebService与服务器端程序进行交互的问题,这篇博客重点关注两个问题,一个是Android应用程序如何与本机文件型数据库SQLite进行交互,另一问题则是如 ...

  3. linux系统下kvm虚拟机的安装

    一 KVM虚拟机简介 KVM是kernel-based Virtual Machine的简称,目前已成为学术界的主流VMM之一.KVM的虚拟化需要硬件支持(如Intel VT技术或者AMD V技术) ...

  4. iOS - 开源框架、项目和学习资料汇总(网络篇)

    网络连接 1. AFNetworking – ASI不升级以后,最多人用的网络连接开源库,[推荐]iOS网络编程之AFNetworking使用,iOS开发下载文件速度计算.2. Alamofire – ...

  5. Yii---使用事物

    YII使用事物的时候,遇到的一些小问题总结:开始事物,后要进行事物提交,才能操作数据库(折腾了一天)具体使用: yii事物的定义:是指作为单个逻辑工作单元执行的一系列操作,要么完全地执行,要么完全地不 ...

  6. Elasticsearch 与 Mongodb 数据同步问题

    1.mongo-connector工具 首先安装python环境 wget http://www.python.org/ftp/python/3.0.1/Python-3.0.1.tgz tar -z ...

  7. uva 10983 Buy one, get the rest free 二分判定层次图

    二分枚举租用飞机的最大花费,然后用小于等于最大花费的边构建层次图(依据时间) 构图思路:   利用二元组(x,y)表示 x天y城市 1. e天有飞机从a城市飞到b城市,能够承载x人,则添加单向边 ( ...

  8. Linux监控远程端口是否开启脚本

    #!/bin/bash #author Liuyueming #date 2017-07-29 #定时检测邦联收单及预付卡系统 pos_num=`nmap 远程IP地址 -p 端口号|sed -n & ...

  9. iOS开发tableView去掉顶部上部空表区域

    tableview中的第一个cell 里上部 有空白区域,大概64像素 在viewDidLoad中加入如下代码 self.automaticallyAdjustsScrollViewInsets = ...

  10. [py]约瑟夫问题-循环队列

    约瑟夫问题(历史战争问题) 直观理解 老外视频讲解 模拟器演示 约瑟夫问题 数学姥公众号 讲的最清楚 背景及,推倒过程讲解得很清晰,旨在提高人们对数据的兴趣 简单说下: 几个人围成一圈(循环队列), ...