图论练习2

内容:路径计数DP,差分约束              

最短路计数

题目大意

  • 给一个n个点m条边的无向无权图,问从1出发到其他每个点的最短路有多少条
  • 有自环和重边,对答案mod100003

解题思路 

  • 设边权为1,跑最短路
  • \left\{\begin{matrix} if\ dis_v>dis_u+w(u,v) & tot_v=tot_u\\ if \ dis_v=dis_u+w(u,v) &tot_v+=tot_u \end{matrix}\right.
  • tot_u 表示1\rightarrow u的路径数
  • 自环和重边不影响最短路

import java.io.*;
import java.math.BigInteger;
import java.util.PriorityQueue;
import java.util.StringTokenizer;public class Main{static long mod=100003;static long inf=Long.MAX_VALUE/2;static Edge[] e;static int[] head;static int cnt;staticclass Edge{int fr,to,nxt;long val;public Edge(int u,int v,long w) {fr=u;to=v;val=w;}}static void addEdge(int fr,int to,long val) {cnt++;e[cnt]=new Edge(fr, to, val);e[cnt].nxt=head[fr];head[fr]=cnt;}staticclass Node{int x;long dis;public Node(int X,long D) {x=X;dis=D;}}public static void main(String[] args) throws IOException{AReader input=new AReader();PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));int n=input.nextInt();int m=input.nextInt();e=new Edge[m<<1|1];head=new int[n+1];long[] dis=new long[n+1];long[] tot=new long[n+1];boolean[] vis=new boolean[n+1];for(int i=1;i<=m;++i) {int u=input.nextInt();int v=input.nextInt();addEdge(u, v, 1);addEdge(v, u, 1);}for(int i=1;i<=n;++i)dis[i]=inf;PriorityQueue<Node> q=new PriorityQueue<Node>((o1,o2)->{if(o1.dis-o2.dis>0)return 1;else if(o1.dis-o2.dis<0)return -1;else return 0;});dis[1]=0;tot[1]=1;q.add(new Node(1, 0));while(!q.isEmpty()) {Node now=q.peek();q.poll();int x=now.x;if(vis[x])continue;vis[x]=true;long disu=now.dis;for(int i=head[x];i>0;i=e[i].nxt) {int v=e[i].to;long w=e[i].val;if(vis[v])continue;if(dis[v]>disu+w) {dis[v]=disu+w;tot[v]=tot[x];q.add(new Node(v, dis[v]));}else if(dis[v]==disu+w) {tot[v]=(tot[x]+tot[v])%mod;}}}for(int i=1;i<=n;++i) {out.println(tot[i]);}out.flush();out.close();}staticclass AReader{BufferedReader bf;StringTokenizer st;BufferedWriter bw;public AReader(){bf=new BufferedReader(new InputStreamReader(System.in));st=new StringTokenizer("");bw=new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException{return bf.readLine();}public String next() throws IOException{while(!st.hasMoreTokens()){st=new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException{//确定下一个token只有一个字符的时候再用return next().charAt(0);}public int nextInt() throws IOException{return Integer.parseInt(next());}public long nextLong() throws IOException{return Long.parseLong(next());}public double nextDouble() throws IOException{return Double.parseDouble(next());}public float nextFloat() throws IOException{return Float.parseFloat(next());}public byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}public void println() throws IOException {bw.newLine();}public void println(int[] arr) throws IOException{for (int value : arr) {bw.write(value + " ");}println();}public void println(int l, int r, int[] arr) throws IOException{for (int i = l; i <= r; i ++) {bw.write(arr[i] + " ");}println();}public void println(int a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(int a) throws IOException{bw.write(String.valueOf(a));}public void println(String a) throws IOException{bw.write(a);bw.newLine();}public void print(String a) throws IOException{bw.write(a);}public void println(long a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(long a) throws IOException{bw.write(String.valueOf(a));}public void println(double a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(double a) throws IOException{bw.write(String.valueOf(a));}public void print(char a) throws IOException{bw.write(String.valueOf(a));}public void println(char a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}}
}

[HAOI2012]ROAD

题目链接

题目大意

  •  n个点m条单向有权边,对每条边求有多少条最短路经过该边
  • 答案取模1000000007

 解题思路

  • 对每个点,求从该点出发到其他点的最短路,将用到的边保留生成新图,其余边无用
  •  对于在新图上的每个点
  • 利用Tuopu求从这个点进入的路径数a,正着累加
  • 利用dfs求从这个点出去的路径数b,倒着累加
  • 对于边u\rightarrow vNum_{u\rightarrow v}+=a_u*b_v\%mod

import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;public class Main{static int n;static int m;static long inf=Long.MAX_VALUE/2;static long mod=1000000007;staticclass Map{public Map() {cnt=0;head=new int[n+1];e=new Edge[m+1];dis=new long[n+1];vis=new boolean[n+1];}int cnt;int[] head;staticclass Edge{int fr,to,nxt;long val;public Edge(int u,int v,long w) {fr=u;to=v;val=w;}}Edge[] e;void addEdge(int fr,int to,long val) {cnt++;e[cnt]=new Edge(fr, to, val);e[cnt].nxt=head[fr];head[fr]=cnt;}staticclass Node{int x;long dis;public Node(int X,long D) {x=X;dis=D;}}long[] dis;boolean[] vis;void Dij(int s) {for(int i=1;i<=n;++i) dis[i]=inf;for(int i=1;i<=n;++i) vis[i]=false;PriorityQueue<Node> q=new PriorityQueue<Node>((o1,o2)->{if(o1.dis-o2.dis>0)return 1;else if(o1.dis-o2.dis<0) return -1;else return 0;});dis[s]=0;q.add(new Node(s, 0));while(!q.isEmpty()) {Node now=q.peek();q.poll();int x=now.x;if(vis[x])continue;long disu=now.dis;vis[x]=true;for(int i=head[x];i>0;i=e[i].nxt){int v=e[i].to;long w=e[i].val;if(vis[v])continue;if(disu+w<dis[v]) {dis[v]=disu+w;q.add(new Node(v,dis[v]));}}}}void Make_Tp() {for(int i=1;i<=cnt;++i) {int u=e[i].fr;int v=e[i].to;long w=e[i].val;if(dis[u]+w==dis[v]) {Tp.addEdge(u, v, w, i);Tp.in[v]++;}}}}staticclass Mapp {public Mapp() {cnt=0;head=new int[n+1];e=new Edge[m+1];in=new int[n+1];a=new long[n+1];b=new long[n+1];}int cnt;int[] head;staticclass Edge{int fr,to,nxt,id;long val;public Edge(int u,int v,long w) {fr=u;to=v;val=w;}}Edge[] e;void addEdge(int fr,int to,long val,int id) {cnt++;e[cnt]=new Edge(fr, to, val);e[cnt].id=id;e[cnt].nxt=head[fr];head[fr]=cnt;}int[] in;//s->i--j<-tlong[] a;  long[] b;void stoi(int s) {Queue<Integer> q=new LinkedList<Integer>();q.add(s);a[s]=1;while(!q.isEmpty()) {int u=q.peek();q.poll();for(int i=head[u];i>0;i=e[i].nxt) {int v=e[i].to;a[v]=(a[v]+a[u])%mod;in[v]--;if(in[v]==0)q.add(v);}}}void jfrt(int u) {//不用建反图跑拓扑if(b[u]!=0)return;for(int i=head[u];i>0;i=e[i].nxt) {int v=e[i].to;jfrt(v);b[u]=(b[u]+b[v])%mod;}b[u]++;//j<-j也算}void getf() {for(int i=1;i<=cnt;++i) {int id=e[i].id;int u=e[i].fr;int v=e[i].to;f[id]=(f[id]+a[u]*b[v]%mod)%mod;}}void clear() {cnt=0;Arrays.fill(head, 0);Arrays.fill(in, 0);Arrays.fill(a, 0);Arrays.fill(b, 0);}}static Map T;static Mapp Tp;static long[] f;static void get(int s) {T.Dij(s);Tp.clear();T.Make_Tp();Tp.stoi(s);Tp.jfrt(s);Tp.getf();}public static void main(String[] args) throws IOException{AReader input=new AReader();PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));n=input.nextInt();m=input.nextInt();T=new Map();Tp=new Mapp();f=new long[m+1];for(int i=1;i<=m;++i) {int u=input.nextInt();int v=input.nextInt();long w=input.nextLong();T.addEdge(u, v, w);}for(int i=1;i<=n;++i) get(i);for(int i=1;i<=m;++i)out.println(f[i]);out.flush();out.close();}staticclass AReader{BufferedReader bf;StringTokenizer st;BufferedWriter bw;public AReader(){bf=new BufferedReader(new InputStreamReader(System.in));st=new StringTokenizer("");bw=new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException{return bf.readLine();}public String next() throws IOException{while(!st.hasMoreTokens()){st=new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException{//确定下一个token只有一个字符的时候再用return next().charAt(0);}public int nextInt() throws IOException{return Integer.parseInt(next());}public long nextLong() throws IOException{return Long.parseLong(next());}public double nextDouble() throws IOException{return Double.parseDouble(next());}public float nextFloat() throws IOException{return Float.parseFloat(next());}public byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}public void println() throws IOException {bw.newLine();}public void println(int[] arr) throws IOException{for (int value : arr) {bw.write(value + " ");}println();}public void println(int l, int r, int[] arr) throws IOException{for (int i = l; i <= r; i ++) {bw.write(arr[i] + " ");}println();}public void println(int a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(int a) throws IOException{bw.write(String.valueOf(a));}public void println(String a) throws IOException{bw.write(a);bw.newLine();}public void print(String a) throws IOException{bw.write(a);}public void println(long a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(long a) throws IOException{bw.write(String.valueOf(a));}public void println(double a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(double a) throws IOException{bw.write(String.valueOf(a));}public void print(char a) throws IOException{bw.write(String.valueOf(a));}public void println(char a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}}
}

逛公园

题目链接

题目大意 

  • 给一个n个点m条边构成的有向带权图,没有自环和重边
  • 1\rightarrow n的最短路长为d,求1\rightarrow n有多少条长度\left [ d,d+k \right ]的路径

解题思路                     

  • 求从1出发的最短路,1\rightarrow u=d_u
  • f[u][x]表示1\rightarrow u=d_u+x,x\leq k,路径个数
  • u\rightarrow v\Rightarrow d_u+x+w(u,v)=d_v+y,y\leq k
  • x=d_v-d_u-w(u,v)+y
  • f[v][y]+=f[u][x]
  • 所以反向建图,dfs(n,y),y\in [0,k]
  • 若最短路上有0环,则会有无穷多路径
  • 若在dfs中,该f[v][y]还在等待递归返回答案时,再次被访问,则有0环
  • 初始dfs(1,0),判断1在不在0环内,在则f[1][0]=\infty,有0环,反之,f[1][0]=1

import java.io.*;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.Vector;public class Main{static int inf=Integer.MAX_VALUE/2;static int md;staticclass Node{int x;int dis;public Node(int X,int D) {x=X;dis=D;}}staticclass Edge{int fr,to,nxt;int val;public Edge(int u,int v,int w) {fr=u;to=v;val=w;}}staticclass Map{Edge[] e;int[] head;int cnt;public Map(int n,int m) {e=new Edge[m<<1|1];head=new int[n+1];cnt=0;}void addEdge(int fr,int to,int val) {cnt++;e[cnt]=new Edge(fr, to, val);e[cnt].nxt=head[fr];head[fr]=cnt;}}static boolean fail=false;static Map T;static Map Tp;static int[] dis;static long[][] f;static boolean[][] inqu;static void dfs(int v,int k) {//disu+x+w(u,v)=disv+k//x=disv-disu-w+kif(fail)return;if(inqu[v][k]) {//这个状态还没处理又绕回来了,k不变,即走了0环fail=true;return;}if(f[v][k]>0)return;inqu[v][k]=true;long res=0;for(int i=Tp.head[v];i>0;i=Tp.e[i].nxt) {int u=Tp.e[i].to;int w=Tp.e[i].val;int x=dis[v]-dis[u]-w+k;if(x<0)continue;dfs(u, x);res=(res+f[u][x])%md;if(fail)return;}f[v][k]=res;inqu[v][k]=false;}public static void main(String[] args) throws IOException{AReader input=new AReader();PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));int O=input.nextInt();while(O>0) {int n=input.nextInt();int m=input.nextInt();int k=input.nextInt();md=input.nextInt();fail=false;T=new Map(n, m);Tp=new Map(n, m);f=new long[n+1][k+1];dis=new int[n+1];inqu=new boolean[n+1][k+1];boolean[] vis=new boolean[n+1];for(int i=1;i<=m;++i) {int u=input.nextInt();int v=input.nextInt();int w=input.nextInt();T.addEdge(u, v, w);Tp.addEdge(v, u, w);}for(int i=1;i<=n;++i)dis[i]=inf;PriorityQueue<Node> q=new PriorityQueue<Node>((o1,o2)->{return o1.dis-o2.dis;});dis[1]=0;q.add(new Node(1, 0));while(!q.isEmpty()) {Node now=q.peek();q.poll();int x=now.x;if(vis[x])continue;vis[x]=true;int disu=now.dis;for(int i=T.head[x];i>0;i=T.e[i].nxt) {int v=T.e[i].to;int w=T.e[i].val;if(vis[v])continue;if(dis[v]>disu+w) {dis[v]=disu+w;q.add(new Node(v, dis[v]));}}}long ans=0;dfs(1,0);f[1][0]=1;for(int i=0;i<=k;++i) {if(fail)break;dfs(n, i);ans=(ans+f[n][i])%md;}if(fail)out.println(-1);else out.println(ans);T=null;Tp=null;inqu=null;dis=null;f=null;O--;}out.flush();out.close();}staticclass AReader{BufferedReader bf;StringTokenizer st;BufferedWriter bw;public AReader(){bf=new BufferedReader(new InputStreamReader(System.in));st=new StringTokenizer("");bw=new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException{return bf.readLine();}public String next() throws IOException{while(!st.hasMoreTokens()){st=new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException{//确定下一个token只有一个字符的时候再用return next().charAt(0);}public int nextInt() throws IOException{return Integer.parseInt(next());}public long nextLong() throws IOException{return Long.parseLong(next());}public double nextDouble() throws IOException{return Double.parseDouble(next());}public float nextFloat() throws IOException{return Float.parseFloat(next());}public byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}public void println() throws IOException {bw.newLine();}public void println(int[] arr) throws IOException{for (int value : arr) {bw.write(value + " ");}println();}public void println(int l, int r, int[] arr) throws IOException{for (int i = l; i <= r; i ++) {bw.write(arr[i] + " ");}println();}public void println(int a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(int a) throws IOException{bw.write(String.valueOf(a));}public void println(String a) throws IOException{bw.write(a);bw.newLine();}public void print(String a) throws IOException{bw.write(a);}public void println(long a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(long a) throws IOException{bw.write(String.valueOf(a));}public void println(double a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(double a) throws IOException{bw.write(String.valueOf(a));}public void print(char a) throws IOException{bw.write(String.valueOf(a));}public void println(char a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}}
}

[SCOI2011]糖果

题目链接

题目大意

  • n个人,k对限制
  • 问在满足限制的条件下,每个人至少有一个糖果时,所需的糖果总数 

解题思路 

  • \left\{\begin{matrix} a=b\Rightarrow a\leq b,b\leq a\Rightarrow a\overset{0}{\rightarrow}b,b\overset{0}{\rightarrow}a\\ a\leq b\Rightarrow a\overset{0}{\rightarrow}b\\ a< b\Rightarrow a+1\leq b\Rightarrow a\overset{1}{\rightarrow}b\\ b\leq a\Rightarrow b\overset{0}{\rightarrow}a\\ b< a\Rightarrow b+1\leq a\Rightarrow b\overset{1}{\rightarrow}a \end{matrix}\right.
  • j将限制转化为边建图后,要满足限制,则要跑最长路
  • 将权为1的边转为权为-1,用Spfa跑最短路
  • 若一个点被更新n次,则出现负环,无解
  • 初始dis_i=-1,表示至少有一个糖果 
  • ans-=\sum_{i=1}^{n}dis_i

import java.io.*;
import java.io.ObjectInputStream.GetField;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.Vector;public class Main{
//	static int inf=Integer.MAX_VALUE/2;static boolean fail=false;staticclass Edge{int fr,to,nxt;int val;public Edge(int u,int v,int w) {fr=u;to=v;val=w;}}staticclass Map{Edge[] e;int[] head;int cnt;int vis;public Map(int n,int m) {e=new Edge[m];head=new int[n+1];cnt=0;vis=0;}void addEdge(int fr,int to,int val) {cnt++;e[cnt]=new Edge(fr, to, val);e[cnt].nxt=head[fr];head[fr]=cnt;}long spfa(int n) {boolean[] inqu=new boolean[n+1];int[] dis=new int[n+1];int[] tot=new int[n+1];Queue<Integer> q=new LinkedList<Integer>();for(int i=1;i<=n;++i) {dis[i]=-1;inqu[i]=true;q.add(i);}while(!q.isEmpty()) {int u=q.peek();q.poll();inqu[u]=false;for(int i=head[u];i>0;i=e[i].nxt) {int v=e[i].to;int w=e[i].val;if(dis[v]>dis[u]+w) {dis[v]=dis[u]+w;tot[v]++;if(tot[v]>=n) {fail=true;break;}if(inqu[v])continue;inqu[v]=true;q.add(v);}}if(fail)break;}if(fail)return 0;long ans=0;for(int i=1;i<=n;++i) {ans-=dis[i];}return ans;}}public static void main(String[] args) throws IOException{AReader input=new AReader();PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));int n=input.nextInt();int m=input.nextInt();Map T=new Map(n, m<<1|1);int[] in=new int[n+1];for(int i=1;i<=m;++i) {int x=input.nextInt();int a=input.nextInt();int b=input.nextInt();//最短路if(x==1) {//a==b=> a<=b,b<=aT.addEdge(a, b, 0);T.addEdge(b, a, 0);}else if(x==2) {//a<b=>a+1<=bif(a==b){out.print("-1");out.flush();out.close();return;}T.addEdge(a, b, -1);}else if(x==3) {//a>=bT.addEdge(b, a, 0);}else if(x==4) {//a>b=>b+1<=aif(a==b){out.print("-1");out.flush();out.close();return;}T.addEdge(b, a, -1);}else {//a<=bT.addEdge(a, b, 0);}}long ans=T.spfa(n);if(fail) {out.print("-1");}else out.print(ans);out.flush();out.close();}staticclass AReader{BufferedReader bf;StringTokenizer st;BufferedWriter bw;public AReader(){bf=new BufferedReader(new InputStreamReader(System.in));st=new StringTokenizer("");bw=new BufferedWriter(new OutputStreamWriter(System.out));}public String nextLine() throws IOException{return bf.readLine();}public String next() throws IOException{while(!st.hasMoreTokens()){st=new StringTokenizer(bf.readLine());}return st.nextToken();}public char nextChar() throws IOException{//确定下一个token只有一个字符的时候再用return next().charAt(0);}public int nextInt() throws IOException{return Integer.parseInt(next());}public long nextLong() throws IOException{return Long.parseLong(next());}public double nextDouble() throws IOException{return Double.parseDouble(next());}public float nextFloat() throws IOException{return Float.parseFloat(next());}public byte nextByte() throws IOException{return Byte.parseByte(next());}public short nextShort() throws IOException{return Short.parseShort(next());}public BigInteger nextBigInteger() throws IOException{return new BigInteger(next());}public void println() throws IOException {bw.newLine();}public void println(int[] arr) throws IOException{for (int value : arr) {bw.write(value + " ");}println();}public void println(int l, int r, int[] arr) throws IOException{for (int i = l; i <= r; i ++) {bw.write(arr[i] + " ");}println();}public void println(int a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(int a) throws IOException{bw.write(String.valueOf(a));}public void println(String a) throws IOException{bw.write(a);bw.newLine();}public void print(String a) throws IOException{bw.write(a);}public void println(long a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(long a) throws IOException{bw.write(String.valueOf(a));}public void println(double a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}public void print(double a) throws IOException{bw.write(String.valueOf(a));}public void print(char a) throws IOException{bw.write(String.valueOf(a));}public void println(char a) throws IOException{bw.write(String.valueOf(a));bw.newLine();}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/665867.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

WPS Office18.7软件日常更新

【应用名称】&#xff1a;WPS Office 【适用平台】&#xff1a;#Android 【软件标签】&#xff1a;#WPS 【应用版本】&#xff1a;18.6.1➡18.7 【应用大小】&#xff1a;160MB 【软件说明】&#xff1a;软件日常更新。WPS Office是使用人数最多的移动办公软件。独有手机阅读模…

正点原子--STM32定时器学习笔记(1)

这部分是笔者对基本定时器的理论知识进行学习与总结&#xff01;&#xff0c;主要记录自己在学习过程中遇到的重难点&#xff0c;其他一些基础点就一笔带过了&#xff01; 1. 定时器概述 1.1 软件定时原理 使用纯软件&#xff08;CPU死等&#xff09;的方式实现定时&#xf…

机器学习_15_贝叶斯算法

文章目录 1 贝叶斯定理相关公式2 朴素贝叶斯算法2.1 朴素贝叶斯算法推导2.2 朴素贝叶斯算法流程 3 高斯朴素贝叶斯4 伯努利朴素贝叶斯5 多项式朴素贝叶斯6 贝叶斯网络6.1 最简单的一个贝叶斯网络6.2 全连接贝叶斯网络6.3 “正常”贝叶斯网络6.4 实际贝叶斯网络&#xff1a;判断…

算法学习——华为机考题库5(HJ31 - HJ35)

算法学习——华为机考题库5&#xff08;HJ31 - HJ35&#xff09; HJ31 单词倒排 描述 对字符串中的所有单词进行倒排。 说明&#xff1a; 1、构成单词的字符只有26个大写或小写英文字母&#xff1b; 2、非构成单词的字符均视为单词间隔符&#xff1b; 3、要求倒排后的单…

LeAPI 后端接口开发 - 发布、下线接口

一、上线接口&#xff08;仅管理员&#xff09; 1. 校验请求参数 2. 判断&#xff08;测试&#xff09;接口是否可以调用 引入调用接口的客户端&#xff08;自己写的 SDK&#xff09;注入客户端实例调用接口 3. 修改数据库中接口的状态 /*** 上线&#xff08;发布&#xff…

爬虫(二)

1.同步获取短视频 1.只要播放地址对Json数据解析&#xff0c;先把列表找出&#xff1a; 2.只想要所有的播放地址&#xff0c;通过列表表达式循环遍历这个列表拿到每个对象&#xff0c;再从一个个对象里面找到Video,再从Video里面找到播放地址(play_addr),再从播放地址找到播放…

动态内存管理 智能指针 shared_ptr、unique_ptr、weak_ptr + 定制删除器

动态内存管理常出现的两种问题&#xff1a; 1.忘记释放内存,造成内存泄漏 2.这块内存还有其他指针指向的情况下&#xff0c;就释放了它&#xff0c;会产生引用非法内存的指针&#xff0c;例如 如果类中有属性指向堆区&#xff0c;做赋值操作时会出现浅拷贝的问题 内存泄漏分…

在jetbrains IDEA/Pycharm/Android Studio中安装官方rust插件,开始rust编程

在idea插件市场搜索rust&#xff1a;JetBrains Marketplace &#xff0c;就可以找到rust插件&#xff1a; jetbrains官方rust插件地址&#xff1a;[Deprecated] Rust - IntelliJ IDEs Plugin | Marketplace 直接在idea中搜索rust好像是搜不到的&#xff1a; 需要在这个插件市场…

【数据结构】二叉树链式结构的实现

简单不先于复杂&#xff0c;而是在复杂之后。 文章目录 1. 二叉树链式结构的实现1.1 前置说明1.2 二叉树的遍历1.2.1 前序、中序以及后序遍历1.2.2 层序遍历 1.3 节点个数以及高度等1.4 二叉树基础oj练习1.5 二叉树的创建和销毁 1. 二叉树链式结构的实现 1.1 前置说明 在学习二…

Cambalache in Ubuntu

文章目录 前言apt install flatpak这很ok后记 前言 gtkmm4相比gtkmm3有很多改革, 代码也干净了许多, 但在windows上开发 有ui设计器那自然方便很多, 但glade又不支持gtkmm4, windows上装Cambalache很是困难. 各种问题都找不到答案.于是 我用VMware虚拟机Ubuntu20.xx安装Cambal…

macOS虚拟机安装全过程的详细教程

macOS虚拟机安装全过程的详细教程 一、安装虚拟机软件 选择软件&#xff1a;首先&#xff0c;你需要选择一个适合macOS的虚拟机软件。在本教程中&#xff0c;我们以VirtualBox为例。下载与安装&#xff1a;访问VirtualBox的官网&#xff0c;下载适用于macOS的安装包。运行安装…

高校建设AI算力平台方案探索

近年来&#xff0c;人工智能行业发展迅速&#xff0c;在自动驾驶、金融、医疗、教育等行业广泛应用。尤其是ChatGPT发布以后更是掀起了生成式AI的热潮&#xff0c;国内各大互联网厂商也相继发布自己的AI大模型。这也造成了大量的AI人才缺口&#xff0c;同时促进了高校的AI专业建…

CSP-202305-2-矩阵运算

CSP-202305-2-矩阵运算&#xff1a;题目链接 知识点一&#xff1a;申请矩阵 1.动态分配 // 申请 int** dynamicArray new int*[rows]; for (int i 0; i < rows; i) {dynamicArray[i] new int[cols]; }// 释放 for (int i 0; i < rows; i) {delete[] dynamicArray[…

解决浏览器端 globalThis is not defined 报错

解决浏览器端 globalThis is not defined 报错 前言解决办法&#xff1a; 前言 在使用低版本火狐浏览器出现报错globalThis is not defined 解决办法&#xff1a; 在vue的index.html 中添加 this.globalThis || (this.globalThis this) <head><script>this.g…

Lambda表达式(匿名函数)

C11中引入了lambda表达式&#xff0c;定义匿名的内联函数。 我们可以直接原地定义函数而不用再跑到外面去定义函数跳来跳去。 同时在stl的排序上也有作用。 [capture] (parameters) mutable ->return-type {statement}下面逐一介绍各个参数的含义. [capture] : 捕获&#…

Java语法学习线程基础

Java语法学习线程基础 大纲 概念创建线程线程终止常用方法用户线程和守护线程线程的七大状态线程的同步互斥锁线程死锁释放锁 具体案例 1.概念 2. 创建线程 第一种&#xff1a; class Cat extends Thread {int time 0;Overridepublic void run() {while (true) {System.o…

重写Sylar基于协程的服务器(5、IO协程调度模块的设计)

重写Sylar基于协程的服务器&#xff08;5、IO协程调度模块的设计&#xff09; 重写Sylar基于协程的服务器系列&#xff1a; 重写Sylar基于协程的服务器&#xff08;0、搭建开发环境以及项目框架 || 下载编译简化版Sylar&#xff09; 重写Sylar基于协程的服务器&#xff08;1、…

红日靶场1搭建渗透

环境搭建 下载好镜像文件并解压&#xff0c;启动vmware 这里我用自己的win7 sp1虚拟机作为攻击机&#xff0c;设置为双网卡NAT&#xff0c;vm2 其中用ipconfig查看攻击机ip地址 设置win7 x64为双网卡&#xff0c;vm1&#xff0c;vm2 设置win08单网卡vm1&#xff0c;win2k3为单…

jupyter notebook更改工作目录的2个细节

详细步骤参考知乎原文&#xff1a; 如何更改Jupyter Notebook的默认工作路径&#xff1f; - 知乎 (zhihu.com​​​​​​) 步骤4中需要删除 #符号和后面的空格&#xff01;一定要删除空格&#xff0c;否则会出现语法错误的报错 步骤5中&#xff0c;经过评论区提醒后&#xf…

蓝桥杯备战——12.PCF8591芯片的使用

目录 1.芯片简介2.读写时序3.控制字4.代码封装库5.原理图分析6.使用示例 1.芯片简介 截取自NXP的PCF8591芯片数据手册&#xff0c;我把重点关注部分划出来了&#xff0c;请务必自行阅读一遍数据手册&#xff01; 2.读写时序 ①器件地址&#xff1a; Bit0决定是读还是写操作&…