青蛙跳杯子
原题链接:问题 1878: [蓝桥杯][2017年第八届真题]青蛙跳杯子
解题思路:将问题简单转化为青蛙和*的换位,使用BFS搜索即可,为避免重复状态使用map存储,可以在O(1)判重
import java.util.*;
public class Main {
static class Fron {
String now;
int step;
int pos;
Fron(String now, int step, int pos) {
this.now = now;
this.pos = pos;
this.step = step;
}
}
static String start, end;
static Queue<Fron> q = new ArrayDeque<Fron>();
static Map<String, Integer> m = new HashMap<String, Integer>