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

焦作市建设委员会网站seo的工作内容

焦作市建设委员会网站,seo的工作内容,江苏省两学一做网站,企业建站做网站队列优化算法 请找出从城市 1 到城市 n 的所有可能路径中,综合政府补贴后的最低运输成本。 如果能够从城市 1 到连通到城市 n, 请输出一个整数,表示运输成本。如果该整数是负数,则表示实现了盈利。如果从城市 1 没有路径可达城市…

队列优化算法

请找出从城市 1 到城市 n 的所有可能路径中,综合政府补贴后的最低运输成本。
如果能够从城市 1 到连通到城市 n, 请输出一个整数,表示运输成本。如果该整数是负数,则表示实现了盈利。如果从城市 1 没有路径可达城市 n,请输出 “unconnected”。


import java.util.*;public class Test {static class Edge{int from;int to;int val;public Edge(int from,int to,int val){this.from=from;this.to=to;this.val=val;}}public static void main(String[] args) {Scanner in=new Scanner(System.in);int n=in.nextInt();int m=in.nextInt();List<List<Edge>> graph=new ArrayList<>();for(int i=0;i<n;i++){graph.add(new ArrayList<>());}for(int i=0;i<m;i++){int from=in.nextInt();int to=in.nextInt();int val=in.nextInt();graph.get(from).add(new Edge(from, to, val));}int[]minDist=new int[n+1];Arrays.fill(minDist,Integer.MAX_VALUE);minDist[1]=0;Queue<Integer> queue=new LinkedList<>();queue.offer(1);boolean[] isInQueue=new boolean[n+1];while(!queue.isEmpty()){int curNode=queue.poll();isInQueue[curNode]=false;for(Edge edge:graph.get(curNode)){if(minDist[edge.to]>minDist[edge.from]+edge.val){minDist[edge.to]=minDist[edge.from]+edge.val;if(!isInQueue[edge.to]){queue.offer(edge.to);isInQueue[edge.to]=true;}}}}if(minDist[n]==Integer.MAX_VALUE){System.out.println("unconnected");}else{System.out.println(minDist[n]);}}}

判断负权回路

负权回路是指一系列道路的总权值为负,这样的回路使得通过反复经过回路中的道路,理论上可以无限地减少总成本或无限地增加总收益。
请找出从城市 1 到城市 n 的所有可能路径中,综合政府补贴后的最低运输成本。同时能够检测并适当处理负权回路的存在。


import java.util.*;public class Test {static class Edge{int from;int to;int val;public Edge(int from,int to,int val){this.from=from;this.to=to;this.val=val;}}public static void main(String[] args) {Scanner in=new Scanner(System.in);int n=in.nextInt();int m=in.nextInt();List<List<Edge>> graph=new ArrayList<>();for(int i=0;i<n;i++){graph.add(new ArrayList<>());}for(int i=0;i<m;i++){int from=in.nextInt();int to=in.nextInt();int val=in.nextInt();graph.get(from).add(new Edge(from, to, val));}int[]minDist=new int[n+1];Arrays.fill(minDist,Integer.MAX_VALUE);minDist[1]=0;Queue<Integer> queue=new LinkedList<>();queue.offer(1);boolean[] isInQueue=new boolean[n+1];int[] count=new int[n+1];count[1]++;boolean flag=false;while(!queue.isEmpty()){int curNode=queue.poll();isInQueue[curNode]=false;for(Edge edge:graph.get(curNode)){if(minDist[edge.to]>minDist[edge.from]+edge.val){minDist[edge.to]=minDist[edge.from]+edge.val;if(!isInQueue[edge.to]){queue.offer(edge.to);count[edge.to]++;isInQueue[edge.to]=true;}if(count[edge.to]==n){flag=true;while (!queue.isEmpty()) {queue.poll();}break;}}}}if(flag){System.out.println("circle");}else if(minDist[n]==Integer.MAX_VALUE){System.out.println("unconnected");}else{System.out.println(minDist[n]);}}}

加了一个count数组,若松弛 n 次以上,则存在负权回路

单源有限最短路

某国为促进城市间经济交流,决定对货物运输提供补贴。共有 n 个编号为 1 到 n 的城市,通过道路网络连接,网络中的道路仅允许从某个城市单向通行到另一个城市,不能反向通行。

网络中的道路都有各自的运输成本和政府补贴,道路的权值计算方式为:运输成本 - 政府补贴。

权值为正表示扣除了政府补贴后运输货物仍需支付的费用;

权值为负则表示政府的补贴超过了支出的运输成本,实际表现为运输过程中还能赚取一定的收益。

请计算在最多经过 k 个城市的条件下,从城市 src 到城市 dst 的最低运输成本

import java.util.*;public class Main {// 基于Bellman_for一般解法解决单源最短路径问题// Define an inner class Edgestatic class Edge {int from;int to;int val;public Edge(int from, int to, int val) {this.from = from;this.to = to;this.val = val;}}public static void main(String[] args) {// Input processingScanner sc = new Scanner(System.in);int n = sc.nextInt();int m = sc.nextInt();List<Edge> graph = new ArrayList<>();for (int i = 0; i < m; i++) {int from = sc.nextInt();int to = sc.nextInt();int val = sc.nextInt();graph.add(new Edge(from, to, val));}int src = sc.nextInt();int dst = sc.nextInt();int k = sc.nextInt();int[] minDist = new int[n + 1];int[] minDistCopy;Arrays.fill(minDist, Integer.MAX_VALUE);minDist[src] = 0;for (int i = 0; i < k + 1; i++) { // Relax all edges k + 1 timesminDistCopy = Arrays.copyOf(minDist, n + 1);for (Edge edge : graph) {int from = edge.from;int to = edge.to;int val = edge.val;// Use minDistCopy to calculate minDistif (minDistCopy[from] != Integer.MAX_VALUE && minDist[to] > minDistCopy[from] + val) {minDist[to] = minDistCopy[from] + val;}}}// Output printingif (minDist[dst] == Integer.MAX_VALUE) {System.out.println("unreachable");} else {System.out.println(minDist[dst]);}}
}
http://www.dtcms.com/wzjs/275796.html

相关文章:

  • 济南做设计公司网站营销策划思路
  • 做淘宝客需要网站吗百度应用搜索
  • 网站开发类百度经验怎么赚钱
  • 如何给自己网站做反链百度刷排名优化软件
  • 德州seo排名seo 优化 服务
  • java里面做网站都要学什么网站排名优化查询
  • 开封旅游网站建设方案策划书免费网站流量统计工具
  • 建委网证书查询北京搜索引擎关键词优化
  • 凡科网官方网站网络优化的工作内容
  • WordPress更换主题残留网络推广优化方案
  • 云建站推荐电子商务软文写作
  • 站内营销推广方式建网站一般多少钱
  • 专业的网站建设设计价格最近的电脑培训班在哪里
  • www开头网站怎么做今日国内新闻最新消息
  • 新疆住房和城乡建设厅网站首页友情链接赚钱
  • 自己创造网站优化大师软件大全
  • 摄影师网站推荐域名注册信息查询whois
  • 南阳做网站优化开发网站用什么软件
  • 厦门企业网站建设电商广告
  • 辽阳市建设行业培训中心网站什么软件比百度搜索好
  • 网站建设 app开发 图片网络营销解释
  • 个体户网站备案浏览器广告投放
  • 网站建设的数据所有权色盲怎么治疗
  • 网站托管共享服务器费用一年多少钱网络推广大概需要多少钱
  • 网站开发专业就业前系军新手怎么做销售
  • 网站建设论文文献杭州网站seo推广
  • 域名续费做网站太原seo推广
  • 动态网站用什么语言做的seo搜索引擎优化试题
  • 西安专业网站开发联系电话十大营销策略
  • 东莞网站建设58小程序商城制作一个需要多少钱