文章
99
粉丝
120
获赞
8
访问
96.2k
class Solution {
public:
vector<double> calcEquation(vector<vector<string>>& equations, vector<double>& values, vector<vector<string>>& queries) {
//把出现的字符映射到数字
int n = 0;
unordered_map<string, int>var;
int m = equations.size();
for(int i = 0; i < m; i++){
if(var.find(equations[i][0])==var.end()){
var[equations[i][0]] = n++;
}
if(var.find(equations[i][1])==var.end()){
var[equations[i][1]] = n++;
}
}
//建图, n*n邻接矩阵
vector<vector<double>>G(n,vector<double>(n,-1.0));
for(int i = 0; i < m; i++){
int u = var[equations[i][0]], v = var[equations[i][1]];
G[u][v] = values[i];
G[v][u] = 1.0/values[i];
}
//floyed,处理出任意点对间的距离
for(int k = 0; k < n; k++){
for(int i = 0...
登录后发布评论
暂无评论,来抢沙发