第四题 0case:
第四题已经知道为什么了,
char c; cin>>c; circle[i] = c;应该是
int c; cin>>c; circle[i] = c;
void solution4(){ int T; cin>>T; vector<string> res; while(T--){ int n; cin>>n; unordered_set<string> S; bool same = false; while(n--){ vector<int> circle(6); for(int i=0;i<6;i++){ char c; cin>>c; circle[i] = c; } sort(circle.begin(),circle.end()); string circle_s; for(auto &item:circle){ circle_s += to_string(item); } if(S.find(circle_s)!=S.end()){ same = true; res.emplace_back("YES"); break; } else S.insert(circle_s); } if(!same) res.emplace_back("NO"); } for(auto &s:res) cout<<s<<endl; }
void solution5(){ long int n,m,T; cin>>n>>m>>T; while(m--){ int x,y,d; cin>>x>>y>>d; G[x][y] = d; final[x]= 0; final[y] = 0; D[x] = INT_MAX; D[y] = INT_MAX; } long int to = Dj(1,n); for(auto &vis:final){ vis.second = 0; } for(auto &dis:D){ dis.second = INT_MAX; } long int re = Dj(n,1); long int res = T*(to+re); cout<<res<<endl; } long int Dj(int start, int end){ priority_queue<pair<long int,int>, vector<pair<long int,int>>, std::greater<pair<long int,int>>> pq; pq.push(make_pair(0,start)); D[start] = 0; while(!pq.empty()){ int k = pq.top().second; long int dis = pq.top().first; pq.pop(); if(k == end) return dis; final[k] = 1; for(auto &near:G[k]){ int u = near.first; int u_dis = near.second; if(!final[u]&&D[u] > dis + u_dis){ D[u] = dis + u_dis; pq.push(make_pair(D[u],u)); } } } return 0; } unordered_map<int,unordered_map<int,int>> G; unordered_map<int,long int> D; unordered_map<int,int> final;求指错!!!!!!!!!!!
全部评论
(1) 回帖