记录编号 553840 评测结果 WWWWWWWWWWWWWW
题目名称 [USACO Feb07] 银色莲花池 最终得分 0
用户昵称 Gravatar城南花已开 是否通过 未通过
代码语言 C++ 运行时间 0.000 s
提交时间 2020-08-27 23:46:47 内存使用 0.00 MiB
显示代码纯文本
  1. # include <iostream>
  2. # include <cstdio>
  3. using namespace std;
  4. int m,n,pool1[31][31],qx[902],qy[902],sum2=0,startx,starty,lh[1500]={0};
  5. int min2=2333333,before1[902],total1=0,sum1[902],a,b,min1=2333333,head=0,tail=1,i,j;
  6. int heng[9]={0,1,2,2,1,-1,-2,-2,-1},shu[9]={0,2,1,-1,-2,-2,-1,1,2},step1[1500];
  7. bool pool2[31][31];
  8. void bfs(){
  9. qx[1]=startx;
  10. qy[1]=starty;
  11. sum1[1]=0;
  12. do{
  13. head++;
  14. pool2[qx[head]][qy[head]]=false;
  15. if(pool1[qx[head]][qy[head]]==4){
  16. total1++;
  17. pool2[qx[head]][qy[head]]=true;
  18. step1[total1]=sum1[head];
  19. a=head;
  20. while(pool1[qx[before1[a]]][qy[before1[a]]]!=3){
  21. if(pool1[qx[before1[a]]][qy[before1[a]]]==0){
  22. lh[total1]++;
  23. }
  24. b=before1[a];
  25. a=b;
  26. }
  27. }
  28. else{
  29. for(i=1;i<=8;i++){
  30. if(qx[head]+heng[i]>=1&&qx[head]+heng[i]<=m&&qy[head]+shu[i]>=1&&qy[head]+shu[i]<=n){
  31. if(pool2[qx[head]+heng[i]][qy[head]+shu[i]]==true){
  32. tail++;
  33. qx[tail]=qx[head]+heng[i];
  34. qy[tail]=qy[head]+shu[i];
  35. before1[tail]=head;
  36. sum1[tail]=sum1[head]+1;
  37. }
  38. }
  39. }
  40. }
  41. }while(head<tail);
  42. }
  43. int main(){
  44. freopen("silvlily.in","r",stdin);
  45. freopen("silvlily.out","w",stdout);
  46. scanf("%d%d",&m,&n);
  47. for(i=1;i<31;i++){
  48. for(int j=1;j<31;j++){
  49. pool2[i][j]=true;
  50. }
  51. }
  52. for(i=1;i<=m;i++){
  53. for(j=1;j<=n;j++){
  54. scanf("%d",&pool1[i][j]);
  55. if(pool1[i][j]==2){
  56. pool2[i][j]=false;
  57. }
  58. if(pool1[i][j]==3){
  59. startx=i;
  60. starty=j;
  61. }
  62. }
  63. }
  64. bfs();
  65. if(total1==0){
  66. printf("%d",-1);
  67. return 0;
  68. }
  69. for(i=1;i<=total1;i++){
  70. if(lh[i]<min1){
  71. min1=lh[i];
  72. }
  73. }
  74. for(i=1;i<=total1;i++){
  75. if(lh[i]==min1){
  76. if(step1[i]<min2)
  77. min2=step1[i];
  78. }
  79. }
  80. for(i=1;i<=total1;i++){
  81. if(lh[i]==min1&&step1[i]==min2){
  82. sum2++;
  83. }
  84. }
  85. printf("%d\n%d\n%d",min1,min2,sum2);
  86. fclose(stdin);
  87. fclose(stdout);
  88. return 0;
  89. }