精華區beta Marginalman 關於我們 聯絡資訊
不小心錯兩次 幹 不然排名更前面 這次5000 名左右 不上不下 我的徽章...什麼時後回來我身邊... q1 三個數字的二進位組合最大的 思路: 全部舉出來 ```cpp class Solution { public: int btd(string bin) { int dec = 0; for (char bit : bin) { dec = dec * 2 + (bit - '0'); } return dec; } string tob(int num) { string binary = ""; while (num > 0) { binary = (num % 2 == 0 ? "0" : "1") + binary; num /= 2; } return binary; } int maxGoodNumber(vector<int>& nums) { string s1 ; string s2 ; string s3 ; s1 = tob(nums[0]); s2 = tob(nums[1]); s3 = tob(nums[2]); string t; t=s1+s2+s3; int a = btd(t); t=(s2+s3+s1); int b = btd(t); t=(s3+s2+s1); int c = btd(t); t=(s1+s3+s2); int d = btd(t); t=(s2+s1+s3); int e = btd(t); t=(s3+s1+s2); int f = btd(t); return max(a ,max(b ,max(c ,max(d ,max(e ,f ) ) ) ) ); } }; ``` q2 給你n個點 還有一些單向的邊 第k個點是有問題的 並且他可以指到的點都會跟著有問題 要把有問題的點頭刪掉 但是如果沒問題的點 指向 有問題的點 那那些有問題的點就不刪 回傳剩下的點 思路: 先對第k點做bfs紀錄 然後再從沒問題的點bfs 只要遇到有問題的點 那就直接回傳原本陣列 不然就遍歷紀錄 看那些可以 ```cpp class Solution { public: vector<int> remainingMethods(int n, int k, vector<vector<int>>& invocations) { vector<int> haha(n); for(int i = 0 ; i < n ; i ++) { haha[i] = i; } unordered_map<int,vector<int>> path; vector<int> indeg(n,0); for(vector<int> kk : invocations) { path[kk[0]].push_back(kk[1]); indeg[kk[1]] ++; } vector<int> passed(n,0); vector<int> sus(n,0); queue<int> qq; qq.push(k); while(!qq.empty()) { int p = qq.front(); qq.pop(); sus[p] = 1; passed[p] = 1; for(int i : path[p]) { indeg[i] --; if(passed[i])continue; qq.push(i); } } for (int i = 0; i < n; i++) { if (sus[i] == 0 ) { qq.push(i); } } vector<int> passed2(n,0); while(!qq.empty()) { int p = qq.front(); qq.pop(); if(sus[p] == 1)return haha; passed2[p] = 1; for(int i : path[p]) { if(passed2[i])continue; qq.push(i); } } vector<int> res; for(int i = 0 ; i < n ; i ++) { if(sus[i] == 0) { res.push_back(i); } } return res; } };``` q3 超難圖論 給你一堆兩個數字的邊的敘述 要你還原出圖 不會 q4 我根本沒看 我沒了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 134.208.237.130 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Marginalman/M.1728191033.A.EF3.html
sixB: 你好厲害 10/06 13:07
wu10200512: 好強 10/06 13:24
sixB: 寶 max可以傳array 10/06 13:54
sixB: max({a,b,c,d,e,f}) 10/06 13:54
oin1104: 阿 好像是 我寫的好醜 10/06 14:03