比赛 20120808 评测结果 EWEEWEEEEE
题目名称 鬼屋惊魂 最终得分 0
用户昵称 Truth.Cirno 运行时间 1.227 s
代码语言 C++ 内存使用 26.99 MiB
提交时间 2012-08-08 12:09:30
显示代码纯文本
  1. #include <cstdio>
  2. using namespace std;
  3.  
  4. const int RUL[5][2]={{0,-1},{0,1},{-1,0},{1,0},{0,0}};
  5.  
  6. int n,que[1000000][3][2],deep[1000000],tar[3][2],tail,head,c;
  7. char map[20][20];
  8.  
  9. bool check(void)
  10. {
  11. int i;
  12. for (i=0;i<n;i++)
  13. if (tar[i][0]!=que[head][i][0]||tar[i][1]!=que[head][i][1])
  14. return(0);
  15. return(1);
  16. }
  17.  
  18. void go(void)
  19. {
  20. int t,t2,i[3],x[3],y[3];
  21. bool done=false,flag;
  22. while (!done&&head>=tail)
  23. {
  24. for (i[0]=0;i[0]<5;i[0]++)
  25. {
  26. if (n>1)
  27. {
  28. for (i[1]=0;i[1]<5;i[1]++)
  29. {
  30. if (n>2)
  31. {
  32. for (i[2]=0;i[2]<5;i[2]++)
  33. {
  34. /**/
  35. for (t=0;t<n;t++)
  36. {
  37. x[t]=que[tail][t][0]+RUL[i[t]][0];
  38. y[t]=que[tail][t][1]+RUL[i[t]][1];
  39. }
  40. flag=true;
  41. for (t=0;t<n;t++)
  42. if (x[t]>=0&&y[t]>=0&&map[x[t]][y[t]]=='#')
  43. {
  44. flag=false;
  45. break;
  46. }
  47. if (!flag)
  48. continue;
  49. for (t=0;t<n;t++)
  50. for (t2=0;t2<n;t2++)
  51. if (t!=t2&&que[tail][t][0]==x[t2]&&que[tail][t][1]==y[t2]&&que[tail][t2][0]==x[t]&&que[tail][t2][1]==y[t])
  52. {
  53. flag=false;
  54. break;
  55. }
  56. if (!flag)
  57. continue;
  58. head++;
  59. for (t=0;t<n;t++)
  60. {
  61. que[head][t][0]=x[t];
  62. que[head][t][1]=y[t];
  63. }
  64. deep[head]=deep[tail]+1;
  65. if (check())
  66. return;
  67. /**/
  68. }
  69. }
  70. else
  71. {
  72. /**/
  73. for (t=0;t<n;t++)
  74. {
  75. x[t]=que[tail][t][0]+RUL[i[t]][0];
  76. y[t]=que[tail][t][1]+RUL[i[t]][1];
  77. }
  78. flag=true;
  79. for (t=0;t<n;t++)
  80. if (map[x[t]][y[t]]=='#')
  81. {
  82. flag=false;
  83. break;
  84. }
  85. if (!flag)
  86. continue;
  87. for (t=0;t<n;t++)
  88. for (t2=0;t2<n;t2++)
  89. if (t!=t2&&que[tail][t][0]==x[t2]&&que[tail][t][1]==y[t2]&&que[tail][t2][0]==x[t]&&que[tail][t2][1]==y[t])
  90. {
  91. flag=false;
  92. break;
  93. }
  94. if (!flag)
  95. continue;
  96. head++;
  97. for (t=0;t<n;t++)
  98. {
  99. que[head][t][0]=x[t];
  100. que[head][t][1]=y[t];
  101. }
  102. deep[head]=deep[tail]+1;
  103. if (check())
  104. return;
  105. /**/
  106. }
  107. }
  108. }
  109. else
  110. {
  111. /**/
  112. for (t=0;t<n;t++)
  113. {
  114. x[t]=que[tail][t][0]+RUL[i[t]][0];
  115. y[t]=que[tail][t][1]+RUL[i[t]][1];
  116. }
  117. flag=true;
  118. for (t=0;t<n;t++)
  119. if (map[x[t]][y[t]]=='#')
  120. {
  121. flag=false;
  122. break;
  123. }
  124. if (!flag)
  125. continue;
  126. for (t=0;t<n;t++)
  127. for (t2=0;t2<n;t2++)
  128. if (t!=t2&&que[tail][t][0]==x[t2]&&que[tail][t][1]==y[t2]&&que[tail][t2][0]==x[t]&&que[tail][t2][1]==y[t])
  129. {
  130. flag=false;
  131. break;
  132. }
  133. if (!flag)
  134. continue;
  135. head++;
  136. for (t=0;t<n;t++)
  137. {
  138. que[head][t][0]=x[t];
  139. que[head][t][1]=y[t];
  140. }
  141. deep[head]=deep[tail]+1;
  142. if (check())
  143. return;
  144. /**/
  145. }
  146. }
  147. tail++;
  148. }
  149. }
  150.  
  151. int main(void)
  152. {
  153. freopen("jumby.in","r",stdin);
  154. freopen("jumby.out","w",stdout);
  155. int i,j,y,x;
  156. scanf("%d %d %d\n",&y,&x,&n);
  157. while (x!=0&&y!=0&&n!=0)
  158. {
  159. for (i=0;i<x;i++)
  160. scanf("%[^\n]\n",&map[i]);
  161. for (i=0;i<x;i++)
  162. for (j=0;j<y;j++)
  163. if (map[i][j]=='a')
  164. {
  165. que[0][0][0]=i;
  166. que[0][0][1]=j;
  167. }
  168. else if (map[i][j]=='b')
  169. {
  170. que[0][1][0]=i;
  171. que[0][1][1]=j;
  172. }
  173. else if (map[i][j]=='c')
  174. {
  175. que[0][2][0]=i;
  176. que[0][2][1]=j;
  177. }
  178. else if (map[i][j]=='A')
  179. {
  180. tar[0][0]=i;
  181. tar[0][1]=j;
  182. }
  183. else if (map[i][j]=='B')
  184. {
  185. tar[1][0]=i;
  186. tar[1][1]=j;
  187. }
  188. else if (map[i][j]=='C')
  189. {
  190. tar[2][0]=i;
  191. tar[2][1]=j;
  192. }
  193. go();
  194. printf("%d\n",deep[head]);
  195. scanf("%d %d %d\n",&y,&x,&n);
  196. }
  197. return(0);
  198. }