个人介绍
增加 238 行删除 239 行
123446 行未改动51525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341```-std=c++14 -O2 -static -Wall -Wextra -Wshadow -Wreturn-type -Werror=return-type -Wl,--stack=268435456```46 行未改动fc \w my.out bf.outif not errorlevel 1 goto looppause``````cpp#include<iostream>#include<queue>#include<string.h>#include<stack>using namespace std;const int N=1e5+5;int hh[N][2],to[N][2],nex[N][2],tot0,tot1,dfn[N],low[N],cnt,val[N][2];int col[N],id,xs[N][2],sum[N],dis[N],vis[N];void add(int u,int v,int w,int x,int k){if(!k){to[++tot0][k]=v;val[tot0][k]=w;xs[tot0][k]=x;nex[tot0][k]=hh[u][k];hh[u][k]=tot0;}else{to[++tot1][k]=v;val[tot1][k]=w;nex[tot1][k]=hh[u][k];hh[u][k]=tot1;}}stack<int>st;void tarjan(int u){dfn[u]=low[u]=++cnt,vis[u]=1;st.push(u);for(int i=hh[u][0];i;i=nex[i][0]){int v=to[i][0];if(!dfn[v]){tarjan(v);low[u]=min(low[u],low[v]);}else if(vis[v])low[u]=min(low[u],dfn[v]);}if(dfn[u]==low[u]){++id;while(st.top()!=u){int v=st.top();col[v]=id,vis[v]=0;st.pop();}col[st.top()]=id;st.pop();}}queue<int>q;void spfa(int u){memset(dis,-1,sizeof dis);vis[u]=1,q.push(u);dis[u]=0;while(!q.empty()){int t=q.front();q.pop(),vis[t]=0;for(int i=hh[t][1];i;i=nex[i][1]){int v=to[i][1];if(dis[v]<dis[t]+val[i][1]+sum[v]){dis[v]=dis[t]+val[i][1]+sum[v];if(!vis[v]) q.push(v),vis[v]=1;}}}}int main(){int n,m,s;cin>>n>>m;for(int i=1;i<=m;i++){int u,v,w;double x;cin>>u>>v>>w>>x;add(u,v,w,x*10,0);}cin>>s;for(int i=1;i<=n;i++)if(!dfn[i]) tarjan(i);for(int u=1;u<=n;u++)for(int i=hh[u][0];i;i=nex[i][0]){int v=to[i][0],w=val[i][0],xx=xs[i][0];if(col[u]==col[v])while(w>0){sum[col[u]]+=w;w=(w*xx)/10;}elseadd(col[u],col[v],w,0,1);}spfa(col[s]);int ans=0;for(int i=1;i<=n;i++)ans=max(ans,dis[col[i]]);cout<<ans;return 0;}```csp-s\2.1 类(class)\1.【6】类的概念及简单应用2.【6】成员函数和运算符重载2.2 STL模板\1.【5】集合(set)2.【5】列表(list),双端队列(deque),优先队列(priority_queue)3.【5】多重集合(multiset)4.【5】映射(map),多重映射(multimap)5.【5】对(pair),元组(tuple)3.数据结构\3.1 线性结构\1.【5】双端栈2.【5】双端队列3.【5】有序队列4.【6】优先队列6.【6】倍增表(ST表)3.2 集合与森林.\1.【6】等价类2.【6】并查集3.【6】树与二叉树的转化--孩子兄弟表示法3.3 特殊树\1.【6】线段树与树状数组2.【6】字典树(trie树)3.【7】笛卡尔树4.【8】二叉平衡树AVL,treap,splay等5.【8】基环树3.4 常见图\1.【5】稀疏图2.【6】偶图(二分图)3.【6】欧拉图4.【6】有向无环图5.【7】连通图与强连通图6.【7】重连通图3.5 哈希表\1.【5】数值哈希函数构造2.【6】排列哈希函数构造3.【6】字符串哈希函数构造4.【6】哈希函数冲突的常用解决方法4.算法\4.1 复杂度分析\1.【6】空间复杂度分析2.【6】时间复杂度分析4.2 基础算法\1.【6】分治算法4.3 排序算法\1.【5】归并排序2.【5】快速排序3.【6】堆排序4.【6】树形选择排序(锦标赛排序)5.【5】桶排序6.【6】基数排序1.【5】字符串匹配算法--KMP4.5 搜索算法\1.【6】搜索的剪枝优化2.【6】记忆化搜索3.【7】启发式搜索4.【7】双向宽度优先搜索5.【7】选代加深搜索6.【8】搜索对象的压缩存储4.6 图论算法\1.【6】Prim和kruskal等求最小生成树算法2.【7】求次小生成树算法3.【6】Dijkstra,bellman_ford、SPFA 等求单源最短路算法4.【7】求单源次短路径算法5.【6】Floyd-Warshall 算法求任意两点间的最短路和传递闭包6.【6】有向无环图的拓扑排序算法7.【6】求欧拉道路和欧拉回路算法8.【6】二分图的构造及其判定算法9.【6】最近公共祖先10.【7】求强联通分量算法11.【7】强连通分量的缩点算法12.【7】求割点、割边算法4.7 动态规划\1.【6】树型动态规划2.【7】状态压缩动态规划3.【8】动态规划的常用优化5.数学\5.1 高中数学\1.【5】代数2.【6】解析几何3.【6】立体几何5.2 初等数论\1.【5】同余式2.【7】欧拉定理和欧拉函数3.【7】费马小定理4.【7】威尔逊定理5.【7】装蜀定理6.【7】逆元7.【7】扩展欧几里得算法8.【7】孙子定理(即中国剩余定理)5.3 组合数学\1.【6】可重集排列2.【6】可重集组合3.【6】错排列、圆排列4.【6】鸽巢原理5.【7】二项式定理6.【7】容斥原理7.【7】卡特兰数5.4 线性代数\1.【5】矩阵概念2.【6】特殊矩阵:稀疏矩阵,三角矩阵,对称矩阵3.【6】矩阵的初等变换4.【6】矩阵的加减乘和转置运算5.【7】线性方程组的高斯消元法\+扫描线,离散化,Manacher,单源次短路,二叉堆1234546 行未改动525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340```-std=c++14 -O2 -static -Wall -Wextra -Wshadow -Wreturn-type -Werror=return-type -Wl,--stack=268435456```46 行未改动fc \w my.out bf.outif not errorlevel 1 goto looppause``````pythonimport tkinter as tkfrom tkinter import messageboximport socketimport threadingimport datetimeimport sysclass ChatClientLite:def __init__(self):self.root = tk.Tk()self.root.title("聊天客户端")self.root.geometry("400x300")self.root.minsize(300, 200)# 基本配置self.font_family = ("微软雅黑", 10)self.create_connection_window()self.root.mainloop()def create_connection_window(self):"""创建连接窗口"""# 配置网格权重以支持窗口缩放self.root.columnconfigure(0, weight=1)self.root.rowconfigure(0, weight=1)frame = tk.Frame(self.root, padx=20, pady=20)frame.pack(expand=True, fill="both")# 服务器地址tk.Label(frame, text="服务器IP:", font=self.font_family).grid(row=0, column=0, sticky="w", pady=5)self.ip_entry = tk.Entry(frame, font=self.font_family)self.ip_entry.grid(row=0, column=1, pady=5, sticky="ew")self.ip_entry.insert(0, "127.0.0.1")# 端口tk.Label(frame, text="端口:", font=self.font_family).grid(row=1, column=0, sticky="w", pady=5)self.port_entry = tk.Entry(frame, font=self.font_family)self.port_entry.grid(row=1, column=1, pady=5, sticky="ew")self.port_entry.insert(0, "8080")# 用户名tk.Label(frame, text="用户名:", font=self.font_family).grid(row=2, column=0, sticky="w", pady=5)self.user_entry = tk.Entry(frame, font=self.font_family)self.user_entry.grid(row=2, column=1, pady=5, sticky="ew")# 配置列权重以支持输入框缩放frame.columnconfigure(1, weight=1)# 连接按钮connect_btn = tk.Button(frame,text="连接",command=self.connect_to_server,bg="#4a90e2",fg="white",font=self.font_family,padx=20,pady=5)connect_btn.grid(row=3, columnspan=2, pady=15)# 提示tk.Label(frame, text="提示: Enter发送消息", font=self.font_family).grid(row=4, columnspan=2)def connect_to_server(self):"""连接到服务器"""try:self.server_ip = self.ip_entry.get()self.port = int(self.port_entry.get())self.username = self.user_entry.get()if not self.username:messagebox.showerror("错误", "用户名不能为空")returnself.socket = socket.socket()self.socket.connect((self.server_ip, self.port))self.root.destroy() # 关闭连接窗口self.create_chat_window() # 打开聊天窗口# 启动消息接收线程threading.Thread(target=self.receive_messages, daemon=True).start()self.chat_win.mainloop()except Exception as e:messagebox.showerror("连接错误", f"无法连接到服务器:\n{str(e)}")def create_chat_window(self):"""创建聊天窗口"""self.chat_win = tk.Tk()self.chat_win.title(f"聊天室 - {self.username}")self.chat_win.geometry("500x350")self.chat_win.minsize(400, 300)# 配置网格权重以支持窗口缩放self.chat_win.columnconfigure(0, weight=1)self.chat_win.rowconfigure(0, weight=1)self.chat_win.rowconfigure(1, weight=0)# 聊天记录框self.chat_frame = tk.Frame(self.chat_win)self.chat_frame.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)self.chat_frame.columnconfigure(0, weight=1)self.chat_frame.rowconfigure(0, weight=1)self.chat_text = tk.Text(self.chat_frame,font=self.font_family,state="disabled",wrap="word")scrollbar = tk.Scrollbar(self.chat_frame, orient="vertical", command=self.chat_text.yview)self.chat_text.configure(yscrollcommand=scrollbar.set)self.chat_text.grid(row=0, column=0, sticky="nsew")scrollbar.grid(row=0, column=1, sticky="ns")# 消息输入框input_frame = tk.Frame(self.chat_win)input_frame.grid(row=1, column=0, sticky="ew", padx=10, pady=5)input_frame.columnconfigure(0, weight=1)self.msg_entry = tk.Text(input_frame,font=self.font_family,height=3,wrap="word")# 定义提示文字self.placeholder_text = "输入消息,Enter发送"# 初始化提示文字self.msg_entry.insert("1.0", self.placeholder_text)self.msg_entry.config(fg="gray")def on_entry_click(event):"""当输入框获得焦点时"""current_text = self.msg_entry.get("1.0", "end-1c")if current_text == self.placeholder_text:self.msg_entry.delete("1.0", "end")self.msg_entry.config(fg="black")def on_focusout(event):"""当输入框失去焦点时"""current_text = self.msg_entry.get("1.0", "end-1c")if not current_text:self.msg_entry.delete("1.0", "end")self.msg_entry.insert("1.0", self.placeholder_text)self.msg_entry.config(fg="gray")# 绑定事件self.msg_entry.bind("<FocusIn>", on_entry_click)self.msg_entry.bind("<FocusOut>", on_focusout)# 绑定按键事件self.msg_entry.bind("<Return>", self.on_enter_key)self.msg_entry.grid(row=0, column=0, sticky="ew")# 发送按钮send_btn = tk.Button(input_frame,text="发送",command=self.send_message,bg="#4a90e2",fg="white",font=self.font_family,padx=15)send_btn.grid(row=0, column=1, padx=(5, 0))def on_enter_key(self, event):"""处理Enter键事件"""self.send_message()return "break" # 阻止默认行为def send_message(self):"""发送消息"""# 获取消息内容,排除提示文字content = self.msg_entry.get("1.0", "end-1c")if content == self.placeholder_text:returnmessage = content.strip()if not message:returnfull_msg = f"{self.username}: {message}\n"try:self.socket.send(full_msg.encode("utf-8"))# 立即显示自己发送的消息self.display_message(full_msg)self.msg_entry.delete("1.0", "end")# 重置提示文字self.msg_entry.insert("1.0", self.placeholder_text)self.msg_entry.config(fg="gray")except Exception as e:messagebox.showerror("发送错误", f"消息发送失败:\n{str(e)}")def receive_messages(self):"""接收消息的线程函数"""while True:try:message = self.socket.recv(1024).decode("utf-8")# 检查是否是封禁消息if "您已被服务器封禁" in message:# 在GUI线程显示封禁消息并退出self.chat_win.after(0, self.handle_ban)break# 检查是否是在线状态测试if message.strip() == "TestOnlineStatus":# 发回在线状态响应try:self.socket.send("TRUE\n".encode("utf-8"))except:passcontinue# 在GUI线程更新界面self.chat_win.after(0, self.display_message, message)except Exception as e:breakdef handle_ban(self):"""处理被封禁的情况"""# 显示封禁消息self.chat_text.config(state="normal")self.chat_text.delete("1.0", "end")self.chat_text.insert("end", "\n\n\n\t\t\t\t您已被服务器封禁!\n")self.chat_text.insert("end", "\t\t\t\t原因: 违反服务器规定\n\n")self.chat_text.insert("end", "\t\t\t\t\t再见!\n")self.chat_text.config(fg="red", font=("微软雅黑", 14, "bold"))self.chat_text.config(state="disabled")# 显示嘲讽对话框self.chat_win.after(1000, self.show_ban_message)def show_ban_message(self):"""显示嘲讽的封禁消息"""messagebox.showerror("封禁通知","您已被服务器封禁!\n\n" +"原因: 您的行为违反了服务器规定\n\n" +"下次请注意言行!\n\n" +"程序将在3秒后自动关闭...")# 3秒后关闭程序self.chat_win.after(3000, self.on_closing)def display_message(self, message):"""在聊天框中显示消息"""self.chat_text.config(state="normal")# 获取当前时间并格式化current_time = datetime.datetime.now().strftime("%H:%M")# 添加时间戳和换行formatted_message = f"[{current_time}] {message}\n"# 确保所有消息都能正常显示self.chat_text.insert("end", formatted_message)# 滚动到最新消息self.chat_text.see("end")self.chat_text.config(state="disabled")def on_closing(self):"""关闭窗口时的处理"""try:self.socket.close()except:passself.chat_win.destroy()sys.exit()if __name__ == "__main__":ChatClientLite()```