is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
use BFS. there are max 8 point to the starting point with MinStep 1.(considering as level 1) from these 8 point, each point will have max 8 point with MinStep 2 to the starting point.(level 2). if the level 2 point hit the level 1 point, skip. and out of boundary skip too. use this method to fill up all 8x8 point. if it hit the destination point during this process, will return the MinStep at that level.
- mwang672 April 04, 2015in C++, using a queue to track each level point, start with starting point,
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
bool validmove(int i,int j,int move,int *ni,int *nj){
if(move==0){
*ni=i+1;
*nj=j+2;
}
else if(move==1){
*ni=i+1;
*nj=j-2;
}
else if(move==2){
*ni=i-1;
*nj=j+2;
}
else if(move==3){
*ni=i-1;
*nj=j-2;
}
else if(move==4){
*ni=i+2;
*nj=j+1;
}
else if(move==5){
*ni=i+2;
*nj=j-1;
}
else if(move==6){
*ni=i-2;
*nj=j+1;
}
else if(move==7){
*ni=i-2;
*nj=j-1;
}
else return false;
if((*ni>=0)&&(*ni<8)&&(*nj>=0)&&(*nj<8))
return true;
else return false;
}
int knightMinStepPath(int sx,int sy,int dx,int dy){
int MinStepPath[8][8];
int nx,ny;
bool flag;
int i,j,cnt,ret=INT32_MAX,MinStep,move;
vector<int> ps;
vector<int> dp;
queue<vector<int>> neighbor;
for(i=0;i<8;i++){
for(j=0;j<8;j++){
MinStepPath[i][j]=INT32_MAX;
}
}
MinStepPath[sx][sy]=0;
if((sx==dx)&&(sy=dy)) {
return 0;
}
ps.push_back(sx);
ps.push_back(sy);
dp.push_back(dx);
dp.push_back(dy);
neighbor.push(ps);
MinStep=0;
while(!neighbor.empty()){
cnt=(int)neighbor.size();
MinStep++;
while(cnt){
ps=neighbor.front();
for(move=0;move<8;move++){
flag=validmove(ps[0],ps[1],move,&nx,&ny);
if(flag){
dp[0]=nx;
dp[1]=ny;
if(MinStepPath[nx][ny]>MinStep){
neighbor.push(dp);
MinStepPath[nx][ny]=MinStep;
if((dx==nx)&&(dy==ny)) {
ret=MinStep;
}
}
}
}
neighbor.pop();
cnt--;
}
}
ps.clear();
dp.clear();
return ret;
}