From: Skullheadx <94652084+Skullheadx@users.noreply.github.com> Date: Sat, 19 Nov 2022 23:22:06 +0000 (-0500) Subject: 2016 S3 attempt not work X-Git-Url: http://git.skullheadx.com/nixos/static/now.html?a=commitdiff_plain;h=59eceff005387a5298ddd302015772f22a59b3ee;p=CCC.git 2016 S3 attempt not work --- diff --git a/Main/C++/2016/S3.cpp b/Main/C++/2016/S3.cpp index 45cf607..1997216 100644 --- a/Main/C++/2016/S3.cpp +++ b/Main/C++/2016/S3.cpp @@ -37,40 +37,41 @@ int main() tree[b].push_back(a); } } - queue>> q; + queue> q; for (int i = 0; i < M; i++) { - q.push({{pho_restaurants[i],0},{}}); + q.push({pho_restaurants[i],0,0}); } - set>> seen; - vector pho_seen; - vector> temp, temp2; + set> seen; + vector temp; int current, length; + long long pho_seen, complete = (pow(10,pho_restaurants.size()) - 1)/9; while (!q.empty()) { - temp = q.front(); - - current = temp[0][0]; - length = temp[0][1]; - pho_seen = temp[1]; + current=q.front()[0], length=q.front()[1], pho_seen = q.front()[2]; q.pop(); - temp2 = {{current},pho_seen}; - - if (find(seen.begin(),seen.end(),temp2) != seen.end()) + temp = {current, pho_seen}; + if (find(seen.begin(),seen.end(),temp) != seen.end()) { continue; } else { - seen.insert(temp2); + seen.insert(temp); } - if (find(pho_restaurants.begin(),pho_restaurants.end(),current)!= pho_restaurants.end() && find(pho_seen.begin(),pho_seen.end(),current)== pho_seen.end()) + if (find(pho_restaurants.begin(),pho_restaurants.end(),current)!= pho_restaurants.end()) { - pho_seen.push_back(current); + long num = pow(10,(find(pho_restaurants.begin(), pho_restaurants.end(),current)-pho_restaurants.begin())); + if ((pho_seen / num)% 10 == 0) + { + pho_seen += num; + + } } - if (pho_seen.size() == pho_restaurants.size()) + cout << current << "|" << length << "|" << pho_seen << endl; + if (pho_seen == complete) { cout << length; return 0; @@ -78,7 +79,7 @@ int main() for (int r = 0; r < tree[current].size();r++) { - q.push({{tree[current][r], length + 1}, pho_seen}); + q.push({tree[current][r], length + 1, pho_seen}); } } return 0; diff --git a/Main/Python/2016/S3.py b/Main/Python/2016/S3.py index eeea985..08c10b2 100644 --- a/Main/Python/2016/S3.py +++ b/Main/Python/2016/S3.py @@ -16,19 +16,22 @@ for i in range(N-1): q = Queue() for i in pho_restaurants: - q.put((i,0, set())) + q.put((i, 0, 0)) seen = set() + +complete = (10 ** len(pho_restaurants) - 1)/9 while not q.empty(): current, length, pho_seen = q.get() - if (current, tuple(pho_seen)) in seen: + if (current, pho_seen) in seen: continue else: - seen.add((current,tuple(pho_seen))) + seen.add((current,pho_seen)) if current in pho_restaurants: - pho_seen.add(current) - if len(pho_seen) == len(pho_restaurants): + if (pho_seen // (10 ** pho_restaurants.index(current))) % 10 == 0: + pho_seen += 10 ** pho_restaurants.index(current) + if pho_seen == complete: print(length) break for r in tree[current]: - q.put((r, length + 1, pho_seen.copy())) + q.put((r, length + 1, pho_seen))