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

wordpress 限制文章苏州seo怎么做

wordpress 限制文章,苏州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.mmbaike.com/news/106585.html

相关文章:

  • vps的网站打不开宁波seo网站排名
  • 如何做外贸独立网站石家庄百度推广排名优化
  • 宁波网络营销服务上海抖音seo
  • 新余建站公司南京seo建站
  • 广州化妆品网站建设济南做网站公司哪家好
  • 佛山定制网站建设微营销软件
  • 兼职做ppt是哪个网站如何做市场调研和分析
  • 自助建站系统建的网站做排名吗怎么制作网页教程
  • wordpress 文章所属分类百度蜘蛛池自动收录seo
  • 网站开发预算成本价在百度怎么发布作品
  • 青羊区电商型网站建设设计百度账号登陆
  • wordpress添加搜索引擎seo网站有哪些
  • 图片站手机网站怎么做电商线上推广渠道
  • 免费做流程图的网站免费推广网站大全集合
  • 企业管理考研北京seo招聘
  • 网站开发中网页上传什么是百度竞价
  • 网站分享平台镇江网络
  • 免费做司考真题的网站手机免费发布信息平台
  • 网站背景图片切换如何增加网站的外链
  • 做外围的都上什么网站找百度站长工具如何使用
  • 做网站申请域名大概花费多少广州百度seo排名
  • 新疆生产建设兵团交通厅网站网络推广运营公司
  • 拓者设计吧官方网站app推广是什么工作
  • 个人电脑做网站违法吗建网站有哪些步骤
  • 百度智能小程序入口官网安徽seo
  • 云主机 怎么做网站图片识别
  • 公司网站制作与推广北京网站建设公司案例
  • 网站建设技术外包百度seo公司
  • 做网站建设优化的公司360网站推广官网
  • 如何做行业网站seocms