http://codeforces.com/contest/3
A
找规律题。但我懒得找,直接暴搜
1 #include<bits/stdc++.h> 2 using namespace std; 3 #define lson l,mid,rt<<1 4 #define rson mid+1,r,rt<<1|1 5 #define sqr(x) ((x)*(x)) 6 typedef long long ll; 7 /*#ifndef ONLINE_JUDGE 8 freopen("1.txt","r",stdin); 9 #endif */ 10 11 int book[15][15]; 12 struct sair{ 13 string str[105]; 14 int co; 15 int x,y; 16 }; 17 18 int dir[8][2]={0,1,1,0,0,-1,-1,0,1,1,-1,-1,1,-1,-1,1}; 19 string D[8]={"R","D","L","U","RD","LU","LD","RU"}; 20 21 sair bfs(sair s){ 22 queue<sair>Q; 23 Q.push(s); 24 sair e; 25 while(!Q.empty()){ 26 s=Q.front(); 27 Q.pop(); 28 for(int i=0;i<8;i++){ 29 e=s; 30 e.x=s.x+dir[i][0]; 31 e.y=s.y+dir[i][1]; 32 if(e.x>=0&&e.x<8&&e.y>=0&&e.y<8&&book[e.x][e.y]!=1){ 33 e.str[e.co]=D[i]; 34 e.co++; 35 Q.push(e); 36 if(book[e.x][e.y]==2){ 37 return e; 38 } 39 book[e.x][e.y]=1; 40 } 41 } 42 } 43 } 44 45 int main(){ 46 #ifndef ONLINE_JUDGE 47 freopen("1.txt","r",stdin); 48 #endif 49 string str,str1; 50 cin>>str; 51 sair s; 52 book[7-(str[1]-'1')][str[0]-'a']=1; 53 s.y=str[0]-'a',s.x=7-(str[1]-'1'),s.co=0; 54 cin>>str1; 55 book[7-(str1[1]-'1')][str1[0]-'a']=2; 56 if(str==str1) {cout<<0<<endl;return 0;} 57 s=bfs(s); 58 cout<<s.co<<endl; 59 for(int i=0;i<s.co;i++){ 60 cout<<s.str[i]<<endl; 61 } 62 }