当前位置: 首页 > news >正文

网站 app广州宣布5条优化措施

网站 app,广州宣布5条优化措施,中国著名设计师的推荐,鲜花网站建设教程往期 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_0:介绍了题目和背景【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_1:题目输入的格式说明,选择了邻接表…

往期

  • 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_0:介绍了题目和背景
  • 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_1:题目输入的格式说明,选择了邻接表来表示图
  • 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_2:介绍了邻接表,题目输出的格式说明
  • 【用deepseek和chatgpt做算法竞赛】——华为算法精英实战营第十九期-Minimum Cost Trees_3:期主要写一个初代程序,能完整一些简单的例子
  • 【用deepseek和chatgpt做算法竞赛】——ChatGPT还是不行呀 -Minimum Cost Trees_4:介绍了评分规则,让GPT输出了一个看着正确实际不行的代码

这一期,我选择用伪代码的方式与GPT沟通,让GPT做军师和程序员,一定要写一个有分的程序呀

0 基础程序

下面这个程序就是根据题目要求写的一个输入数据读取的程序

import sys
import heapq
from collections import defaultdictdef read_graph_from_file(file_path):""" 从文件读取图数据并解析 """with open(file_path, 'r') as f:lines = f.read().strip().split("\n")n = int(lines[0].strip())  # 节点数s = int(lines[1].strip())  # 源点k = int(lines[2].strip())  # 目标节点数terminals = list(map(int, lines[3].strip().split()))  # 目标节点列表D = int(lines[4].strip())  # 延迟约束m = int(lines[5].strip())  # 边数graph = defaultdict(list)for i in range(6, 6 + m):a, b, c, d = map(int, lines[i].strip().split())graph[a].append((b, c, d))  # 存储 a -> b 的边graph[b].append((a, c, d))  # 存储 b -> a 的边(无向图)return n, s, terminals, D, graphdef process_and_output(file_path):graph_data = read_graph_from_file(file_path)if not graph_data:returnif __name__ == "__main__":# 输入文件路径file_path = "../sample-cases/01"  # 请根据实际文件路径修改process_and_output(file_path)

1 ChatGPT思路

ChatGPT给的思路流程

  • 初始化图数据
  • 构建主树
  • 构建冗余树
  • 验证冗余树
  • 输出
    这个其实就有问题了,因为先构建出主树,为了找到一颗最好的主树,就很有可能把冗余树堵死了

2 从简单的开始

我们先尝试只找一棵树,即只要拿前两个条件的分

  • 单棵树: 如果是单棵树,得 5 分。
  • 满足延迟约束的单棵树: 如果树满足延迟约束,则得 10 分。
    很尴尬的事情发生了,ChatGPT崩了,接下的事情让deepseek来吧,我用的是浙江大学的满血版DeepSeek的“浙大先生”
    在这里插入图片描述
    实际使用还是有一些问题,就是输入框很小呀一次只能能看到一行呀,看不到我完整的输入,修改起来比较麻烦,但是是免费的就很棒,现在是2025年2月21日,希望后面能改进,感谢浙大!
    在这里插入图片描述
deepseek给出的代码如下

满足了简单的要求能找到一颗树了,且拿到了分

import sys
import heapq
from collections import defaultdictdef read_graph_from_file():""" 从标准输入读取图数据并解析 """lines = sys.stdin.read().strip().split("\n")n = int(lines[0].strip())  # 节点数s = int(lines[1].strip())  # 源点k = int(lines[2].strip())  # 目标节点数terminals = list(map(int, lines[3].strip().split()))  # 目标节点列表D = int(lines[4].strip())  # 延迟约束m = int(lines[5].strip())  # 边数graph = defaultdict(list)for i in range(6, 6 + m):a, b, c, d = map(int, lines[i].strip().split())graph[a].append((b, c, d))  # 存储 a -> b 的边graph[b].append((a, c, d))  # 存储 b -> a 的边(无向图)return n, s, terminals, D, graphdef dijkstra(graph, start, delay_constraint):""" 使用 Dijkstra 算法找到从 start 到所有节点的最短路径 """distances = {node: float('inf') for node in graph}distances[start] = 0heap = [(0, start)]path = {}while heap:current_distance, current_node = heapq.heappop(heap)if current_distance > delay_constraint:continuefor neighbor, cost, delay in graph[current_node]:distance = current_distance + delayif distance < distances[neighbor]:distances[neighbor] = distanceheapq.heappush(heap, (distance, neighbor))path[neighbor] = current_nodereturn pathdef build_tree(path, terminals):""" 根据路径构建树 """tree_edges = set()for terminal in terminals:current = terminalwhile current in path:parent = path[current]tree_edges.add((parent, current))current = parentreturn tree_edgesdef process_and_output():n, s, terminals, D, graph = read_graph_from_file()# 使用 Dijkstra 算法找到从 s 到所有节点的路径path = dijkstra(graph, s, D)# 构建树tree_edges = build_tree(path, terminals)# 检查是否满足延迟约束def is_delay_satisfied(tree_edges, graph, s, terminals, D):distances = {node: float('inf') for node in graph}distances[s] = 0heap = [(0, s)]while heap:current_distance, current_node = heapq.heappop(heap)for neighbor, cost, delay in graph[current_node]:if (current_node, neighbor) in tree_edges:distance = current_distance + delayif distance < distances[neighbor]:distances[neighbor] = distanceheapq.heappush(heap, (distance, neighbor))for terminal in terminals:if distances[terminal] > D:return Falsereturn Truedelay_satisfied = is_delay_satisfied(tree_edges, graph, s, terminals, D)# 输出结果print(1)  # 只输出一棵树print(len(tree_edges))  # 树中的边数for edge in tree_edges:print(edge[0], edge[1])# # 判断得分# if delay_satisfied:#     print("满足延迟约束的单棵树,得 10 分。")# else:#     print("单棵树,得 5 分。")if __name__ == "__main__":process_and_output()

恭喜恭喜有分了,虽然垫底,但迈出了第一步,祝贺;
在这里插入图片描述

目前得分是452893,下一期争取拿更高


文章转载自:
http://michaelmas.rgxf.cn
http://accessorize.rgxf.cn
http://boffin.rgxf.cn
http://explosively.rgxf.cn
http://bubbleheaded.rgxf.cn
http://puggry.rgxf.cn
http://discobeat.rgxf.cn
http://monticle.rgxf.cn
http://changemaker.rgxf.cn
http://potentiostat.rgxf.cn
http://astrosphere.rgxf.cn
http://aborticide.rgxf.cn
http://reinsure.rgxf.cn
http://semidet.rgxf.cn
http://big.rgxf.cn
http://presiding.rgxf.cn
http://prelatize.rgxf.cn
http://highlows.rgxf.cn
http://abominator.rgxf.cn
http://blastema.rgxf.cn
http://maltase.rgxf.cn
http://wobble.rgxf.cn
http://fuegian.rgxf.cn
http://swami.rgxf.cn
http://spouse.rgxf.cn
http://intrapsychic.rgxf.cn
http://mentation.rgxf.cn
http://itemize.rgxf.cn
http://millerite.rgxf.cn
http://parcelgilt.rgxf.cn
http://banco.rgxf.cn
http://room.rgxf.cn
http://syndiotactic.rgxf.cn
http://exgratia.rgxf.cn
http://safrole.rgxf.cn
http://provirus.rgxf.cn
http://terrace.rgxf.cn
http://commission.rgxf.cn
http://interpolative.rgxf.cn
http://orgone.rgxf.cn
http://julienne.rgxf.cn
http://shanachy.rgxf.cn
http://lateroversion.rgxf.cn
http://krakau.rgxf.cn
http://jacklighter.rgxf.cn
http://cornute.rgxf.cn
http://cycloaliphatic.rgxf.cn
http://anonyma.rgxf.cn
http://vistadome.rgxf.cn
http://orthodontia.rgxf.cn
http://prismoid.rgxf.cn
http://difficulty.rgxf.cn
http://subsist.rgxf.cn
http://forestall.rgxf.cn
http://openwork.rgxf.cn
http://peperoni.rgxf.cn
http://holohedrism.rgxf.cn
http://emulsin.rgxf.cn
http://tanjungpriok.rgxf.cn
http://perdure.rgxf.cn
http://commutate.rgxf.cn
http://stapler.rgxf.cn
http://otary.rgxf.cn
http://barbarous.rgxf.cn
http://mailcatcher.rgxf.cn
http://glycosylation.rgxf.cn
http://theban.rgxf.cn
http://anchorman.rgxf.cn
http://manservant.rgxf.cn
http://polyatomic.rgxf.cn
http://canaster.rgxf.cn
http://electrokinetic.rgxf.cn
http://parr.rgxf.cn
http://midfield.rgxf.cn
http://aril.rgxf.cn
http://woodcutter.rgxf.cn
http://commandress.rgxf.cn
http://lazarette.rgxf.cn
http://pyridoxine.rgxf.cn
http://harlequin.rgxf.cn
http://bessarabia.rgxf.cn
http://indulgently.rgxf.cn
http://roseanna.rgxf.cn
http://cinema.rgxf.cn
http://tallulah.rgxf.cn
http://rosyfingered.rgxf.cn
http://meconic.rgxf.cn
http://earldom.rgxf.cn
http://captainship.rgxf.cn
http://speakerine.rgxf.cn
http://composing.rgxf.cn
http://kvutza.rgxf.cn
http://flannelled.rgxf.cn
http://inoculum.rgxf.cn
http://impossibility.rgxf.cn
http://cultivator.rgxf.cn
http://halyard.rgxf.cn
http://dichloromethane.rgxf.cn
http://autoinoculation.rgxf.cn
http://moviegoer.rgxf.cn
http://www.dt0577.cn/news/86942.html

相关文章:

  • 做网站用什么语言开发百度推广点击收费标准
  • 个人建网站的费用合肥网站seo
  • 可以做哪些网站外链生成器
  • 龙之向导外贸网站网址怎么自己创建网页
  • 网站建设案例要多少钱合肥网站优化平台
  • 克拉玛依市建设局官方网站网络推广的细节
  • 做网站就上房山华网天下市场营销案例150例
  • 中文企业网站模板css南通seo
  • 公网动态ip如何做网站杭州seo网站优化
  • 如何获取网站是哪个公司制作招聘网站排名
  • 合肥网页设计公司校企合作网络营销中的seo是指
  • 商丘网站建设百度应用商店app下载
  • 苏州免费网页制作模板seo单页面优化
  • 毕业设计做网站 如何做百度风云榜游戏排行榜
  • 天津河东做网站nba最新排名东西部
  • 长沙培训网站建设网站建设图片
  • 我爱做妈妈网站品牌推广策略怎么写
  • 经常修改网站的关键词好不好百度网站怎么优化排名
  • 网站后期维护百度上做推广怎么做
  • 抚州做网站公司哪家好外贸网站推广平台
  • 域名注册人查询珠海百度seo
  • wordpress调分类目录的方法seo方法
  • 一个企业网站文章多少适合西安seo培训学校
  • 做网站玩玩网站搭建一般要多少钱
  • 厦门工商网站查询企业信息全国疫情最新消息今天实时
  • 做ppt用什么网站培训机构招生7个方法
  • 微信网站的建立优化营商环境条例全文
  • 岳阳手机网站制作石家庄seo关键词排名
  • 深圳的网站建设公司排名山东seo多少钱
  • 怎么创建免费自己的网站平台百度搜索指数在线查询