当前位置:网站首页>[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
边栏推荐
- Excellent Kalman filter detailed article
- es6的foreach与some的循环遍历
- Acl2021 best paper released, from ByteDance
- Text processing tool in shell, cut [option parameter] filename Description: the default separator is the built-in variable of tab, awk [option parameter] '/pattern1/{action1}filename and awk
- Metasploit-永恒之蓝攻击
- Cannot start after installing MySQL 5.7.27 in CentOS 7? (Language bash)
- Preparation for Android interview (including the whole process of interview, interview preparation, interview questions and materials, etc.)
- Huawei switch dual uplink networking smart Link Configuration Guide
- 数学推理题:张王李赵陈五对夫妇聚会,见面握手
- Matlab-绘制叠加阶梯图和线图
猜你喜欢

Anaconda installation (very detailed)

Snowflake vs. databricks who is better? The latest war report in 2022
![Shell函数、系统函数、basename [string / pathname] [suffix] 可以理解为取路径里的文件名称 、dirname 文件绝对路径、自定义函数](/img/3d/d7276d2010f1d77a3bd572cc66eced.png)
Shell函数、系统函数、basename [string / pathname] [suffix] 可以理解为取路径里的文件名称 、dirname 文件绝对路径、自定义函数

线代003

Anchor free detector: centernet

Xiandai 004

Overview of PCL modules (1.6)

Decision tree principle and case application - Titanic survival prediction

3D restoration paper: shape painting using 3D generative advantageous networks and recurrent revolutionary networks

3D face reconstruction and dense alignment with position map progression network
随机推荐
Metaaploit-后渗透技知识
VS2019+CUDA11.1新建项目里没有CUDA选项
Anaconda安装(非常详细)
【英雄哥六月集训】第 28天: 动态规划
Discussion on a problem
sql注入
Pyautogui realizes automatic office -rpa small case
FSM onehot answer record
【Flutter】SharedPreferences使用
There is no CUDA option in vs2019+cuda11.1 new project
Preparation for Android interview (including the whole process of interview, interview preparation, interview questions and materials, etc.)
Color segmentation using kmeans clustering
Snowflake vs. databricks who is better? The latest war report in 2022
pillow的原因ImportError: cannot import name ‘PILLOW_VERSION‘ from ‘PIL‘,如何安装pillow<7.0.0
Acl2021 best paper released, from ByteDance
How to create a.Net image with diagnostic tools
程序的翻译和执行,从编辑、预处理、编译、汇编、链接到执行
pytorch的安装(非常详细)
Shell变量、系统预定义变量$HOME、$PWD、$SHELL、$USER、自定义变量、特殊变量$n、$#、$*、[email protected]、$?、env看所有的全局变量值、set看所有变量
Hugo learning notes