Cat and Mouse Blue Bridge cup/hand speed/violence practice (violent search)

Source: Internet
Author: User

Cat and Mouse Blue Bridge cup/hand speed/Violence Practice Contest "The cat and the mouse move in the squares of the 10*10, for example: *...* ..... *...*. .......... ...*. C ..... *.....* ......... m......* .... * * * ..... *.*...... C= Cat (cat) m= Mouse (MOUSE) *= obstacle. = Open space cats and mice walk one block per second, and if they are in the same lattice at the end of a second, we call them "meet." Note that "to wear" is not a meeting. The cat and mouse move the same way: usually along a straight line, the next step if it will go up or out of bounds, with 1 seconds to do a right turn 90 degrees. At first they were all facing the north. Programmed to calculate how many seconds later they meet. "Input format" 10 lines, format as above "output format" Meet time t. If there is no solution, output-1. "Sample Input" *...* ..... *...* .......... .......... ...*. C ..... *.....* ......... m......* .... * * * ..... *.*......
1 /*2 idea: If the cat and the mouse do not meet, then it must be the cat in a certain lattice along a certain direction repeatedly walked more than 2 times and3 so is the mouse. 4 */ 5#include <iostream>6#include <cstring>7#include <cstdio>8#include <algorithm>9 using namespacestd;Ten  One Charmp[ the][ the]; A  - Const intLeft_dir =1; - Const intRight_dir =2; the Const intup =3; - Const intDown =4; - Const intMouse =1; - Const intCat =0; +  - structnode{ +     intx, y; A     intdir; at node () { -DIR =Up ; -     } -      -     BOOLflag[ the][ the][5];//record whether the current grid has passed in a certain direction -      in     voidInitintXinty) { -memset (Flag,false,sizeof(flag)); to          This->x =x; +          This->y =y; -Flag[x][y][up] =true; the     } * }; $ Panax NotoginsengNode nd[2]; - intCNT =0; the  + BOOLMoveinti) { A     intx=nd[i].x, y=nd[i].y; the     intNewdir; +     Switch(nd[i].dir) { -          CaseUp : $x-=1; $Newdir =Right_dir; -              Break; -          CaseDown : thex+=1; -Newdir =Left_dir;Wuyi              Break; the          CaseLeft_dir: -y-=1; WuNewdir =Up ; -              Break; About          CaseRight_dir: $y+=1; -Newdir =Down ; -              Break; -     } A     if(Mp[x][y]! ='*'){ +nd[i].x =x; theND[I].Y =y; -}Else { $Nd[i].dir =Newdir; the     } the      the     if(!Nd[i].flag[x][y][nd[i].dir]) { theNd[i].flag[x][y][nd[i].dir] =true; -         return true;  in}Else return false; the } the  About voidTest () { the     BOOLFlag =true, flag1=false, flag2=false; the      while(flag) { the         if(nd[cat].x = = nd[mouse].x && nd[cat].y = = nd[mouse].y) Break; +         if(!Move (cat)) -Flag1 =true; the         if(!Move (mouse))BayiFlag2 =true; the++CNT; the         if(Flag1 && flag2) flag =false; -     } -     if(flag) printf ("%d\n", CNT); the     Elseprintf"-1\n"); the } the  the intMain () { -Memset (MP,'*',sizeof(MP)); the      for(intI=1; i<=Ten; ++i) { thescanf"%s", mp[i]+1); theMp[i][strlen (mp[i]+1)+1] ='*';94          for(intj=1; j<=Ten; ++j) { the             if(mp[i][j]=='C'){ the Nd[cat].init (i, j); theMP[I][J] ='.';98             } About             Else if(Mp[i][j] = ='M'){ - Nd[mouse].init (i, j);101MP[I][J] ='.';102             }103         }104 GetChar (); the     }106 test ();107     return 0;108 }109 /* the *...*.....111 ......*... the ...*...*..113 .......... the ...*. C .... the *.....*... the ...*......117 .. m......*118 ...*.*....119 .*.*...... - */

Cat and Mouse Blue Bridge cup/hand speed/violence practice (violent search)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.