classSolution{publicdouble[]calcEquation(List<List<String>> equations,double[] values,List<List<String>> queries){// 1. 统计所有出现的字符,并赋予对应的 indexint count =0;Map<String,Integer> map =newHashMap<>();for(List<String> list : equations){for(String s : list){if(!map.containsKey(s)){map.put(s, count++);}}}// 1. 邻接矩阵,初始化double[][] graph =newdouble[count +1][count +1];for(String s : map.keySet()){int x = map.get(s);graph[x][x]=1.0;// 自身相除得0;}int index =0;// 由已知等式,更新矩阵值for(List<String> list : equations){String a = list.get(0);String b = list.get(1);int aa = map.get(a);int bb = map.get(b);double value = values[index++];graph[aa][bb]= value;graph[bb][aa]=1/ value;}// 2. 通过 Floyd 算法进行计算for(int i =0; i <= count; i++){for(int j =0; j <= count; j++){for(int k =0; k <= count; k++){// Case 1: 已出现过if(j == k || graph[j][k]!=0){continue;}// Case 2: 传递赋值 j / i = x, i / k = y ==> j / k = x * yif(graph[j][i]!=0&& graph[i][k]!=0){graph[j][k]= graph[j][i]* graph[i][k];}}}}// 3. 查询矩阵得到答案double[] res =newdouble[queries.size()];for(int i =0; i < res.length; i++){List<String> q = queries.get(i);String a = q.get(0);String b = q.get(1);// 字符串存在判断if(map.containsKey(a)&& map.containsKey(b)){double ans = graph[map.get(a)][map.get(b)];// 未知,则取 -1.0res[i]=(ans ==0)?-1.0: ans;}else{// 未出现字符,也取 -1.0res[i]=-1.0;}}return res;}}
ANDRITZ to supply gasification plant and biomass handling line to Klabin’s Puma II project in Brazil.国际技术集团公司安德里茨收到KLabin的订单,为其位于巴西的Ortigueira浆厂提供一台完整的生物质气化炉和一条新的生物质处理线。International technology…