if (s.find(x) != s.end())
时间: 2024-05-24 10:10:14 浏览: 8
This code checks if the element 'x' is present in the set 's'.
Here, 's' is a set of elements and we are using the 'find' function of the set to check if 'x' is present in it. If 'x' is present, the 'find' function returns an iterator to the element. If 'x' is not present, the 'find' function returns an iterator to the end of the set.
So, if the iterator returned by the 'find' function is not equal to the end iterator of the set (s.end()), it means that 'x' is present in the set 's'.
相关问题
if (s.find(x) != s.end()) { return true; }
This code checks if a key 'x' exists in a set 's'. The 'find' function of a set returns an iterator to the element if it is found, else it returns an iterator to the end of the set. So, if 'x' is found in the set, the condition 's.find(x) != s.end()' will evaluate to true and the function will return true. Otherwise, it will return false.
void Hungarian::SubX_AddY() { int i, j, t; double Delta; set<int> VisitedX, VisitedY; /* Để ý rằng: VisitedY = {y \ Trace[y] khác -1} VisitedX = {start} giao match(VisitedY) = {start} giao {matchY[y] Trace[y] khác -1} */ VisitedX.insert(start); for (j = 0; j < k; j++) { if (Trace[j] != -1) { VisitedX.insert(matchY[j]); VisitedY.insert(j); } }Delta = maxC; for (i = 0; i < k; i++) { if (VisitedX.find(i) != VisitedX.end()) { for (j = 0; j < k; j++) { if ((VisitedY.find(j) == VisitedY.end()) && (GetC(i, j) < Delta)) Delta = GetC(i, j); } } }for (t = 0; t < k; t++) { //trừ trọng số những cạnh liên thuộc với VisitedX đi Delta if (VisitedX.find(t) != VisitedX.end()) Fx[t] = Fx[t] + Delta; //Cộng trọng số những cạnh liên thuộc với VisitedY lên Delta if (VisitedY.find(t) != VisitedY.end()) Fy[t] = Fy[t] - Delta; } }
这段代码是匈牙利算法中的"SubX_AddY"步骤,用于更新节点权值。具体来说,它的作用是从未被匹配的点中找出与已被匹配的点相邻且边权最小的点,然后更新所有与这些点相邻的点的权值。这个过程会涉及到两个向量Fx和Fy,它们分别表示未被匹配的点和已被匹配的点的权值。在这个过程中,我们先将所有与已被匹配的点相邻的点加入VisitedX和VisitedY中,然后遍历VisitedX中的所有点,找到与之相邻且未被匹配的点中边权最小的点,记为Delta,然后更新所有与VisitedX和VisitedY相邻的点的权值。具体来说,对于VisitedX中的点,我们将它们的权值加上Delta,对于VisitedY中的点,我们将它们的权值减去Delta。这样做的目的是为了使已被匹配的点的权值尽量小,从而使匹配的代价最小化。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
import re,tkinter,requests,threading,tqdm as tt root = tkinter.Tk() root.title('在线视频解析') root.geometry('500x590+550+350') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0'} ac = tkinter.Listbox(root, width=50, height=20, font=('黑体', 12)) ac.grid(row=2, columnspan=10, sticky="n" + "s" + "w" + "e") def sousuo(): i = b1.get() ac.delete(0, 'end') def extract_music_info(content): p = '|' content = re.sub(p, '', content, flags=re.S) pattern = re.compile('subject.*?href="(.*?)">(.*?)
', flags=re.S) return pattern.findall(content) def search_music(): url = 'https://www.hifini.com/search-' + i + '-1.htm' response = requests.get(url=url, headers=headers) return response.text def update_listbox(music_list): for music in music_list: pppp = music[1] + ":" + music[0] ac.insert('end', pppp) content = search_music() music_list = extract_music_info(content) update_listbox(music_list) def xiazzi(): def download_music(): ppp = ac.get(ac.curselection()) pp = re.search('thread.*?htm', ppp) v = pp.group() url1 = 'https://www.hifini.com/' + v response = requests.get(url=url1, headers=headers) ppp = response.text l2 = re.search('<script>.*?title:..(.*?).,.*?author:.(.*?).,.*?url:..(.*?).,', ppp, flags=re.S) p = 'https://www.hifini.com/' + l2.group(3) response = requests.get(url=p, headers=headers, stream=True) # 设置 stream=True 以启用流式下载 total_size = int(response.headers.get('Content-Length')) music_name = '{}-{}.mp3'.format(l2.group(2), l2.group(1)) progress_bar = tt.tqdm(total=total_size, unit='B', unit_scale=True) # 创建进度条 with open(music_name, 'wb') as f: for data in response.iter_content(chunk_size=1024): progress_bar.update(len(data)) # 更新进度条 f.write(data) progress_bar.close() # 关闭进度条 print(music_name) threading.Thread(target=download_music).start() a1 = tkinter.Label(root, text='音乐下载器', anchor="center", font=('黑体', 24)) a1.grid(row=0, columnspan=10, sticky="n" + "s" + "w" + "e") b1 = tkinter.Entry(root, width=35, font=('黑体', 16), ) b1.grid(row=1, column=3, padx=15) search_button = tkinter.Button(root, text='搜索', command=sousuo) search_button.grid(row=1, column=4) download_button = tkinter.Button(root, text='下载', command=xiazzi) download_button.grid(row=3, column=4) root.mainloop() 添加 判断下载的文件是不是m4a如果就转为MP3,root上添加下载进度条![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
帮我增加进度条import io import re import tkinter import requests import threading from pydub import AudioSegment root = tkinter.Tk() root.title('在线视频解析') root.geometry('500x590+550+350') headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0'} ac = tkinter.Listbox(root, width=50, height=20, font=('黑体', 12)) ac.grid(row=2, columnspan=10, sticky="n" + "s" + "w" + "e") def sousuo(): i = b1.get() ac.delete(0, 'end') def extract_music_info(content): p = '|' content = re.sub(p, '', content, flags=re.S) pattern = re.compile('subject.*?href="(.*?)">(.*?)
', flags=re.S) return pattern.findall(content) def search_music(): url = 'https://www.hifini.com/search-' + i + '-1.htm' response = requests.get(url=url, headers=headers) return response.text def update_listbox(music_list): for music in music_list: pppp = music[1] + ":" + music[0] ac.insert('end', pppp) content = search_music() music_list = extract_music_info(content) update_listbox(music_list) def xiazzi(): def download_music(): ppp = ac.get(ac.curselection()) pp = re.search('thread.*?htm', ppp) v = pp.group() url1 = 'https://www.hifini.com/' + v response = requests.get(url=url1, headers=headers) ppp = response.text l2 = re.search('<script>.*?title:..(.*?).,.*?author:.(.*?).,.*?url:..(.*?).,', ppp, flags=re.S) p = 'https://www.hifini.com/' + l2.group(3) response = requests.get(url=p, headers=headers) l3 = response.content music_name = '{}-{}.mp3'.format(l2.group(2), l2.group(1)) if l3.startswith(b'\x00\x00\x00\x20\x66\x74\x79\x70'): audio = AudioSegment.from_file(io.BytesIO(l3), format='m4a') audio.export(music_name, format='mp3') else: with open(music_name, 'wb') as f: f.write(l3) print(music_name) threading.Thread(target=download_music).start() a1 = tkinter.Label(root, text='音乐下载器', anchor="center", font=('黑体', 24)) a1.grid(row=0, columnspan=10, sticky="n" + "s" + "w" + "e") b1 = tkinter.Entry(root, width=35, font=('黑体', 16), ) b1.grid(row=1, column=3, padx=15) search_button = tkinter.Button(root, text='搜索', command=sousuo) search_button.grid(row=1, column=4) download_button = tkinter.Button(root, text='下载', command=xiazzi) download_button.grid(row=3, column=4) root.mainloop()![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)