当前位置:网站首页>[brother hero's June training] day 27: picture
[brother hero's June training] day 27: picture
2022-07-27 10:21:00 【If I were Wen Shuai】
Series articles
【 Brother hero training in June 】 The first 01 God : Array
【 Brother hero training in June 】 The first 02 God : character string
【 Brother hero training in June 】 The first 03 God : Sort
【 Brother hero training in June 】 The first 04 God : greedy
【 Brother hero training in June 】 The first 05 God : Double pointer
【 Brother hero training in June 】 The first 06 God : The sliding window
【 Brother hero training in June 】 The first 07 God : Hash
【 Brother hero training in June 】 The first 08 God : The prefix and
【 Brother hero training in June 】 The first 09 God : Two points search
【 Brother hero training in June 】 The first 10 God : An operation
【 Brother hero training in June 】 The first 11 God : matrix
【 Brother hero training in June 】 The first 12 God : Linked list
【 Brother hero training in June 】 The first 13 God : Double linked list
【 Brother hero training in June 】 The first 14 God : Stack
【 Brother hero training in June 】 The first 15 God : Binary tree
【 Brother hero training in June 】 The first 16 God : queue
【 Brother hero training in June 】 The first 17 God : Breadth first search
【 Brother hero training in June 】 The first 18 God : Trees
【 Brother hero training in June 】 The first 19 God : Binary tree
【 Brother hero training in June 】 The first 20 God : Binary search tree
【 Brother hero training in June 】 The first 21 God : Pile up ( Priority queue )
【 Brother hero training in June 】 The first 22 God : Ordered set
【 Brother hero training in June 】 The first 23 God : Dictionary tree
【 Brother hero training in June 】 The first 24 God : Line segment tree
【 Brother hero training in June 】 The first 25 God : Tree array
【 Brother hero training in June 】 The first 26 God : Union checking set
【 Brother hero training in June 】 The first 27 God : chart
List of articles
chart
Graphs are often used to represent and store information with “ Many to many ” The data of the relationship , Is a very important data structure .
One 、 The path with the highest probability
1514. The path with the highest probability
class Solution {
int maxn = 10010;
List<List<Edge>> edge = new ArrayList<List<Edge>>(maxn);
class Edge{
int to;
double val;
Edge(){
}
Edge(int t,double v){
this.to=t;
this.val=v;
}
}
public double bfs(int start,int end){
double[] dis = new double[maxn];
int i;
for(i=0;i<maxn;++i){
dis[i]=0.00d;
}
dis[start]=1.00d;
Queue<Integer> q = new ArrayDeque<Integer>();
q.add(start);
while(!q.isEmpty()){
Integer u = q.remove();
int len = edge.get(u).size();
for(i=0;i<len;++i){
int v = edge.get(u).get(i).to;
double d = dis[u]*(edge.get(u).get(i).val);
if(d>dis[v]){
dis[v]=d;
q.add(v);
}
}
}
return dis[end];
}
public double maxProbability(int n, int[][] edges, double[] succProb, int start, int end) {
int i;
for(i=0;i<maxn;++i){
edge.add(new ArrayList<Edge>());
}
for(i=0;i<edges.length;++i){
if(succProb[i]<=0){
continue;
}
int u = edges[i][0];
int v = edges[i][1];
double w = succProb[i];
edge.get(u).add(new Edge(v,w));
edge.get(v).add(new Edge(u,w));
}
return bfs(start,end);
}
}
Two 、 Keepsake delivery
class Solution {
int[][] dir = new int[][]{
{
-1,0},{
0,1},{
1,0},{
0,-1}
};
public int conveyorBelt(String[] matrix, int[] start, int[] end) {
int i,j;
int m=matrix.length;
int n = matrix[0].length();
int[][] grid = new int [110][110];
for(i=0;i<m;i++){
for(j=0;j<n;j++){
if(matrix[i].charAt(j)=='^'){
grid[i][j]=0;
}
else if(matrix[i].charAt(j)=='>'){
grid[i][j]=1;
}
else if(matrix[i].charAt(j)=='v'){
grid[i][j]=2;
}
else if(matrix[i].charAt(j)=='<'){
grid[i][j]=3;
}
}
}
int u = start[0]*n+start[1];
int[] dis = new int[10010];
for(i=0;i<n*m;++i){
dis[i]=100000000;
}
dis[u]=0;
Deque<Integer> q = new ArrayDeque<Integer>();
q.add(u);
while(!q.isEmpty()){
Integer f = q.remove();
int x = f/n;
int y = f%n;
for(i=0;i<4;++i){
int tx = x+dir[i][0];
int ty = y+dir[i][1];
if(tx<0||ty<0||tx==m||ty==n){
continue;
}
int next = tx*n+ty;
int nextd = dis[f]+((grid[x][y]==i?0:1));
if(nextd < dis[next]){
dis[next] = nextd;
q.add(next);
}
}
}
return dis[end[0]*n+end[1]];
}
}
3、 ... and 、 T The frog's position in seconds
1377. T The frog's position in seconds
class Solution {
int maxn = 110;
List<List<Integer>> e = new ArrayList<List<Integer>>(maxn);
double ans = 0.00d;
public void inite(){
for(int i=0;i<maxn;i++){
e.add(new ArrayList<Integer>());
}
}
public void dfs(int u,int fat,double p,int step,int maxstep,int target){
int i,cnt=0;
for(i =0; i<e.get(u).size(); ++i){
if(e.get(u).get(i)!=fat){
++cnt;
}
}
if(step <= maxstep){
if(u==target){
if(cnt ==0 && step <= maxstep){
ans = p;
} else if(cnt>=1 && step == maxstep){
ans = p;
}
}
}
if(step == maxstep){
return ;
}
for(i=0; i<e.get(u).size(); ++i){
if(e.get(u).get(i)!=fat){
dfs(e.get(u).get(i),u,p*1.0/cnt,step+1,maxstep,target);
}
}
}
public double frogPosition(int n, int[][] edges, int t, int target) {
inite();
int i;
for(i=0; i<edges.length; ++i){
int u = edges[i][0];
int v = edges[i][1];
e.get(u).add(v);
e.get(v).add(u);
}
dfs(1,0,1,0,t,target);
return ans;
}
}
summary
边栏推荐
- vs2019社区版下载教程(详细)
- Uninstall cuda11.1
- Shell流程控制(重点)、if 判断、case 语句、let用法、for 循环中有for (( 初始值;循环控制条件;变量变化 ))和for 变量 in 值 1 值 2 值 3… 、while 循环
- warning package.json: No license field报错
- Anchor Free检测器:CenterNet
- Two architectures of ETL (ETL architecture and ELT Architecture)
- 【英雄哥六月集训】第 28天: 动态规划
- Preparation for Android interview (including the whole process of interview, interview preparation, interview questions and materials, etc.)
- hugo学习笔记
- Sound processing - Mel frequency cepstrum coefficient (MFCC)
猜你喜欢

Configuration of pytorch deep learning environment based on cuda10.0

FTP 服务器

Matlab底层源代码实现图像的中值滤波(用于消除图像上一些杂点)

Shell的read 读取控制台输入、read的使用

备战金九银十Android面试准备(含面试全流程,面试准备工作面试题和资料等)

Open3d library installation, CONDA common instructions, importing open3d times this error solving environment: failed with initial frozen solve Retrying w

NFS 服务器的搭建

Ant高级-task

3D face reconstruction and dense alignment with position map progression network

Live countdown 3 days sofachannel 29 P2P based file and image acceleration system Dragonfly
随机推荐
Oracle RAC 19C PDB instance is down
samba服务器
Matlab draws the system response under different damping
Metaspolit
Shell integrated application cases, archiving files, sending messages
Food safety | the more you eat junk food, the more you want to eat it? Please keep this common food calorimeter
【英雄哥六月集训】第 27天: 图
Matlab-实时编辑器介绍
hugo学习笔记
NFT system development - Tutorial
【英雄哥六月集训】第 24天: 线段树
About new_ Online_ Judge_ 1081_ Thoughts on Goldbach's conjecture
hdu5289(Assignment)
Based on LSM tree idea Net 6.0 C # write a kV database (case version)
Different binary conversion of MATLAB
Understanding and code implementation of Se (sequence and exception) module
文件上传漏洞绕过方法
语音数据采集-实时语音数据可视化
Sub query of database performance series
【英雄哥六月集训】第 23天: 字典树