UVA572 Oil Deposits DFS求解

小白書上經典DFS題目。

1. 遞歸實現

// from: https://www.cnblogs.com/huaszjh/p/4686092.html#include <stdio.h>
#include <string.h>
#define maxn 105
unsigned char data[maxn][maxn];
int m, n, vis[maxn][maxn];void dfs(int x, int y, int ans) {if (x < 0 || x >= m || y < 0 || y >= n) return; //出界if (vis[x][y] > 0 || data[x][y] == '*') return; //非'@'或已經訪問vis[x][y] = ans; //連通分量編號for (int k = -1; k <= 1; k++) {for (int t = -1; t <= 1; t++) {if (k != 0 || t != 0) { //自身格子不需要重復判斷dfs(x + k, y + t, ans);}}}
}#define DEBUG
int main() {
#ifdef DEBUGconst char* input_txt_pth = "F:/zhangzhuo/debug/OJ/UVA-572.txt";freopen(input_txt_pth, "r", stdin);
#endifint i, j;while (scanf("%d %d", &m, &n) && m &&n) {int count = 0; //連通塊memset(vis, 0, sizeof(vis));for (i = 0; i < m; i++) {scanf("%s", data[i]);}for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {//對未訪問且為`@`的格子進行訪問if (vis[i][j] == 0 && data[i][j] == '@') {dfs(i, j, ++count);}}}printf("%d\n", count);
#ifdef DEBUGfor (i = 0; i < m; i++) {for (j = 0; j < n; j++) {printf("%3d", vis[i][j]);}printf("\n");}printf("\n");
#endif}return 0;
}

2. 遞歸dfs函數用迭代實現
每個節點的dfs遞歸調用,改成用stack容器就地計算,是個while循環,本質上還是棧,但是避免了遞歸時嵌套產生的開銷造成的潛在風險。

C++的stack、vector容器用起來比較順手。另外就是把坐標簡單封裝為一個結構體。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stack>
#include <vector>typedef struct Coord {char x, y;
} Coord;#define DEBUG
int main() {
#ifdef DEBUGconst char* input_txt_pth = "F:/zhangzhuo/debug/OJ/UVA-572.txt";freopen(input_txt_pth, "r", stdin);
#endifint m, n, i, j;#define maxn 105unsigned char data[maxn][maxn];int vis[maxn][maxn];while (scanf("%d %d", &m, &n) && m &&n) {int count = 0; //連通塊memset(vis, 0, sizeof(vis));for (i = 0; i < m; i++) {scanf("%s", data[i]);}std::stack<Coord> stk;Coord cd;std::vector<Coord>offset;cd.x = -1; cd.y = -1; offset.push_back(cd);cd.x = -1; cd.y = 0; offset.push_back(cd);cd.x = -1; cd.y = 1; offset.push_back(cd);cd.x = 0; cd.y = -1; offset.push_back(cd);cd.x = 0; cd.y = 1; offset.push_back(cd);cd.x = 1; cd.y = -1; offset.push_back(cd);cd.x = 1; cd.y = 0; offset.push_back(cd);cd.x = 1; cd.y = 1; offset.push_back(cd);for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {cd.x = i; cd.y = j;if (vis[cd.x][cd.y] > 0 || data[cd.x][cd.y] != '@') continue;count++;stk.push(cd);while (!stk.empty()) {cd = stk.top();stk.pop();vis[cd.x][cd.y] = count;Coord tmp;for (size_t k = 0; k < offset.size(); k++) {tmp.x = cd.x + offset[k].x;tmp.y = cd.y + offset[k].y;if (tmp.x < 0 || tmp.x >= m || tmp.y < 0 || tmp.y >= n) continue;if (vis[tmp.x][tmp.y] > 0 || data[tmp.x][tmp.y] != '@') continue;stk.push(tmp);}}}}printf("%d\n", count);#ifdef DEBUGfor (i = 0; i < m; i++) {for (j = 0; j < n; j++) {printf("%3d", vis[i][j]);}printf("\n");}printf("\n");
#endif}return 0;
}

3.純C,DFS非遞歸,自定義棧ADT,函數指針

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>typedef struct Coord Coord;
struct Coord {char x, y;
};typedef struct CoordOffset CoordOffset;
struct CoordOffset {size_t num;int* x;int* y;
};typedef struct ListNode ListNode;
struct ListNode
{ListNode* next;void* data;
};typedef struct Stack Stack;struct Stack {ListNode* head;size_t len;void(*push_coord)(Stack* stk, Coord* coord);void (*pop_coord)(Stack* stk);void (*top_coord)(Stack* stk, Coord* coord);
};void stack_push_coord(Stack* stk, Coord* coord) {ListNode* new_head = (ListNode*)malloc(sizeof(ListNode));/* new_head->data = coord; */new_head->data = (Coord*)malloc(sizeof(ListNode));memcpy(new_head->data, coord, sizeof(Coord));new_head->next = stk->head;stk->head = new_head;stk->len++;
}void stack_pop_coord(Stack* stk) {if (stk->head != NULL) {ListNode* new_head = stk->head->next;free(stk->head->data);free(stk->head);stk->head = new_head;stk->len--;}
}void stack_top_coord(Stack* stk, Coord* coord) {if (stk->head != NULL) {Coord* t_coord = (Coord*)(stk->head->data);coord->x = t_coord->x;coord->y = t_coord->y;}
}void make_stack(Stack** _stk) {Stack* stk = (Stack*)malloc(sizeof(Stack));stk->head = NULL;stk->len = 0;stk->push_coord = stack_push_coord;stk->pop_coord = stack_pop_coord;stk->top_coord = stack_top_coord;/* write back */*_stk = stk;
}void free_stack(Stack* stk) {ListNode* cur = stk->head;ListNode* temp;size_t i;for (i = 0; i < stk->len; i++) {temp = cur->next;free(cur->data);free(cur);cur = temp;}free(stk);stk = NULL;
}void make_8coord_offset(CoordOffset** _offset) {CoordOffset* offset = (CoordOffset*)malloc(sizeof(CoordOffset));offset->num = 8;offset->x = (int*)malloc(sizeof(int)*offset->num);offset->y = (int*)malloc(sizeof(int)*offset->num);offset->x[0] = -1; offset->y[0] = -1;offset->x[1] = -1; offset->y[1] =  0;offset->x[2] = -1; offset->y[2] =  1;offset->x[3] =  0; offset->y[3] = -1;offset->x[4] =  0; offset->y[4] =  1;offset->x[5] =  1; offset->y[5] = -1;offset->x[6] =  1; offset->y[6] =  0;offset->x[7] =  1; offset->y[7] =  1;/* write back */*_offset = offset;
}void free_coord_offset(CoordOffset* offset) {if (offset) {if (offset->x) {free(offset->x);offset->x = NULL;}if (offset->y) {free(offset->y);offset->y = NULL;}free(offset);offset = NULL;}
}/* #define DEBUG */
int main() {
#ifdef DEBUGconst char* input_txt_pth = "F:/zhangzhuo/debug/OJ/UVA-572.txt";freopen(input_txt_pth, "r", stdin);
#endifint m, n, i, j;size_t k;#define maxn 105unsigned char data[maxn][maxn];int vis[maxn][maxn];/* here we use 8 neighbours */CoordOffset* offset = NULL;make_8coord_offset(&offset);while (scanf("%d %d", &m, &n) && m &&n) {int count = 0; /* 連通塊 */memset(vis, 0, sizeof(vis));for (i = 0; i < m; i++) {scanf("%s", data[i]);}/* std::stack<Coord> stk; */Stack* stk;make_stack(&stk);Coord cd;for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {cd.x = i; cd.y = j;if (vis[cd.x][cd.y] > 0 || data[cd.x][cd.y] != '@') continue;count++;/* stk.push(cd); */stack_push_coord(stk, &cd);/* while (!stk.empty()) { */while(stk->len!=0) {/* cd = stk.top(); *//* stack_top_coord(stk, &cd); */stk->top_coord(stk, &cd);/* stk.pop(); *//* stack_pop_coord(stk); */stk->pop_coord(stk);vis[cd.x][cd.y] = count;Coord tmp;for (k = 0; k < offset->num; k++) {tmp.x = cd.x + offset->x[k];tmp.y = cd.y + offset->y[k];if (tmp.x < 0 || tmp.x >= m || tmp.y < 0 || tmp.y >= n) continue;if (vis[tmp.x][tmp.y] > 0 || data[tmp.x][tmp.y] != '@') continue;/* stk.push(tmp); *//* stack_push_coord(stk, &tmp); */stk->push_coord(stk, &tmp);}}}}free_stack(stk);printf("%d\n", count);#ifdef DEBUGfor (i = 0; i < m; i++) {for (j = 0; j < n; j++) {printf("%3d", vis[i][j]);}printf("\n");}printf("\n");
#endif}free_coord_offset(offset);return 0;
}

4.DFS+并查集實現

#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>int fa[10500];
int m, n, cnt, vis[105][105];
char mp[105][105];
int find(int x) {if (fa[x] == x) return x;fa[x] = find(fa[x]);return fa[x];
}void merge(int x, int y) {int fx = find(x);int fy = find(y);if (fx == fy) return;fa[fx] = fy;
}void dfs(int x, int y, int fx, int fy) {if (x < 0 || x >= m || y < 0 || y >= n) return;if (vis[x][y] || mp[x][y] == '*') return;vis[x][y] = 1;/* cout<<"x || y || fx || fy : "<<x<<" || "<<y<<" || "<<fx<<" || "<<fy<<endl; */if (fx != -1) {merge(x*m + y, fx*m + fy);}int i, j;for (i = -1; i < 2; i++) {for (j = -1; j < 2; j++) {if (!i && !j) continue;dfs(x + i, y + j, x, y);}}
}/* #define LOCAL */
int main() {
#ifdef LOCALconst char* input_txt = "F:/zhangzhuo/debug/OJ/UVA-572.txt";freopen(input_txt, "r", stdin);
#endifint i, j;while (scanf("%d%d", &m, &n) == 2 && m && n) {cnt = 0;memset(vis, 0, sizeof(vis));for (i = 0; i < m; i++) {scanf("%s", mp[i]);}for (i = 0; i < 10500; i++) {fa[i] = i;}for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {if (!vis[i][j] && mp[i][j] == '@') {dfs(i, j, -1, -1);cnt++;}}}printf("%d\n", cnt);#ifdef LOCALfor (i = 0; i < m; i++) {for (j = 0; j < n; j++) {printf("%3d", vis[i][j]);}printf("\n");}printf("\n");
#endif}return 0;
}

5.DFS+并查集+不使用全局變量+簡單封裝為結構體
修改自 UVA572 (并查集解法) 。這種寫法有點問題:已經用了dfs,dfs里用并查集多此一舉,如果用并查集就不應該遞歸調用dfs。

#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>typedef struct FSU_Node {int p;    /* parent id */int rank;int vis; /* group(connected component) id */
} FSU_Node;/*
get node's root id
@param x: node id
@param nodes: all nodes in map
*/
int fus_find(int x, FSU_Node* nodes) {if (nodes[x].p == x) return x;nodes[x].p = fus_find(nodes[x].p, nodes);return nodes[x].p;
}/*
merge two node groups
@param a: a node from one node group
@param b: a node from another node group
*/
void fus_union(int a, int b, FSU_Node* nodes)
{int ra = fus_find(a, nodes); /* ra: root id of a */int rb = fus_find(b, nodes); /* rb: root id of b */if (ra == rb) {return;}if (nodes[ra].rank > nodes[rb].rank){nodes[rb].p = ra;}else {if (nodes[ra].rank == nodes[rb].rank){nodes[rb].rank++;}nodes[ra].p = rb;}
}typedef struct ImageSize {int w, h;
} ImageSize;typedef struct Coord {int row, col;
} Coord;void fus_dfs(const Coord* pt, const Coord* f_pt, FSU_Node* nodes, ImageSize* sz, unsigned char* mp) {int row = pt->row;int col = pt->col;int f_row = f_pt->row;int f_col = f_pt->col;if (row < 0 || row >= sz->h || col < 0 || col >= sz->w) return;int id = row * sz->w + col;int fid = f_row * sz->w + f_col;/* if (vis[id] || mp[id] == '*') return; */if (nodes[id].vis || mp[id] == '*') return;/* vis[id] = 1; */nodes[id].vis = 1;if (f_row != -1) {fus_union(id, fid, nodes);}int i, j;Coord neighbor;for (i = -1; i < 2; i++) {for (j = -1; j < 2; j++) {if (!i && !j) continue;neighbor.row = row + i;neighbor.col = col + j;fus_dfs(&neighbor, pt, nodes, sz, mp);}}
}/*#define LOCAL*/
int main() {
#ifdef LOCALconst char* input_txt = "F:/zhangzhuo/debug/OJ/UVA-572.txt";freopen(input_txt, "r", stdin);
#endif#define MAXN 105int m, n, cnt, i, j;/* int vis[MAXN*MAXN]; */unsigned char mp[MAXN*MAXN];FSU_Node nodes[MAXN*MAXN];int idx;while (scanf("%d%d", &m, &n) == 2 && m && n) {cnt = 0;/* memset(vis, 0, sizeof(int)*MAXN*MAXN); */for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * n + j;scanf(" %c", &mp[idx]);/* printf("! %c !", mp[idx]); */}}for (i = 0; i < m*n; i++) {nodes[i].p = idx;nodes[i].rank = 1;nodes[i].vis = 0;}ImageSize im_sz;im_sz.h = m;im_sz.w = n;Coord pt;Coord f_pt;f_pt.row = -1;f_pt.col = -1;for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * n + j;/* if (!vis[idx] && mp[idx] == '@') { */if (!nodes[idx].vis && mp[idx] == '@') {/* dfs(i, j, -1, -1); */pt.row = i;pt.col = j;/* fus_dfs(&pt, &f_pt, nodes, &im_sz, vis, mp); */fus_dfs(&pt, &f_pt, nodes, &im_sz, mp);cnt++;}}}printf("%d\n", cnt);#ifdef LOCALfor (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * m + j;/* printf("%3d", vis[idx]); */printf("%c", mp[idx]);}printf("\n");}printf("\n");
#endif}return 0;
}

這里的教訓是,如果在雙重for循環中使用變量x、y來表示坐標,容易把2維度坐標->1維坐標的計算算錯。使用row,col能減少犯錯可能;
另外就是數據讀取,這里改成%c,則需要過濾掉換行符\n,方法是scanf時的格式串首部添加空格:scanf(" %c", &xx)

6. 并查集,去掉了DFS
思路:遍歷每個像素點,每個像素點用并查集算法合并周邊8鄰域中為'@'的像素點。再次遍歷,統計每個'@'像素對應的等價類(root節點)的值。第三次遍歷,把第二次統計的值當中cnt數大于0的累計,就是區域個數。在統計連通域個數的時候順帶把每個連通域id(像素的parent值)修改為從1開始嚴格單調增的序列,開啟LOCALLOCAL_DEBUG宏可以看到。

和通常用的模板寫法略有差別,比如返回root的遞歸終止條件,比如root初值。

不得不說,uDebug是個好東西。

#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>typedef struct FSU_Node {int p;    /* parent id */int rank;
} FSU_Node;/*
get node's root id
@param x: node id
@param nodes: all nodes in map
*/int fus_find(int x, FSU_Node* nodes) {if (nodes[x].p == x) {return x;}nodes[x].p = fus_find(nodes[x].p, nodes);return nodes[x].p;
}/*
merge two node groups
@param a: a node from one node group
@param b: a node from another node group
*/
void fus_union(int a, int b, FSU_Node* nodes)
{int ra = fus_find(a, nodes); /* ra: root id of a */int rb = fus_find(b, nodes); /* rb: root id of b */if (ra == rb) {return;}if (nodes[ra].rank > nodes[rb].rank) {nodes[rb].p = ra;}else {if (nodes[ra].rank == nodes[rb].rank) {nodes[rb].rank++;}nodes[ra].p = rb;}
}/* #define LOCAL */
/* #define LOCAL_DEBUG */
int main() {
#ifdef LOCALconst char* input_txt = "F:/zhangzhuo/debug/OJ/UVA-572.txt";freopen(input_txt, "r", stdin);
#endif#define MAXN 105int m, n, cnt, i, j, k;int shift_x[8] = { -1, -1, -1,  0, 0,  1, 1, 1 };int shift_y[8] = { -1,  0,  1, -1, 1, -1, 0, 1 };unsigned char mp[MAXN*MAXN];FSU_Node nodes[MAXN*MAXN];int idx;while (scanf("%d%d", &m, &n) == 2 && m && n) {cnt = 0;for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * n + j;scanf(" %c", &mp[idx]);}}for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * n + j;nodes[idx].p = idx;nodes[idx].rank = 1;}}for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * n + j;if (mp[idx] != '@') continue;for (k = 0; k < 8; k++) {int row = i + shift_x[k];int col = j + shift_y[k];int neighbor_idx = row * n + col;if (row < 0 || row >= m || col < 0 || col >= n || mp[neighbor_idx] != '@') continue;fus_union(idx, neighbor_idx, nodes);}}}int bowl[MAXN*MAXN] = { 0 };int label_cnt = 0;for (i = 0; i < m*n; i++) {if (mp[i] != '@') continue;int t = fus_find(i, nodes);nodes[i].p = t;if (bowl[t] == 0) {label_cnt++;bowl[t] = label_cnt;}   }printf("%d\n", label_cnt);#ifdef LOCAL_DEBUG/* print out debug info */for (i = 0; i < m; i++) {for (j = 0; j < n; j++) {idx = i * n + j ;if (mp[idx] == '@') {/* printf("%3d", fus_find(idx, nodes)); *//* printf("%3d", nodes[idx].p); */printf("%3d", bowl[nodes[idx].p]);}else {printf("%3c", '*');}}printf("\n");}printf("\n");
#endif}return 0;
}

轉載于:https://www.cnblogs.com/zjutzz/p/11017619.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/247776.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/247776.shtml
英文地址,請注明出處:http://en.pswp.cn/news/247776.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

HTML 表格中的行合并與列合并

colspan是橫向合并&#xff1b;rowspan是縱向合并。colspan是“column span&#xff08;跨列&#xff09;”的縮寫。colspan屬性用在td標簽中&#xff0c;用來指定單元格橫向跨越的列數&#xff1a;單元格1 單元格2 單元格3 單元格4 該例通過把colspan設為“3”, 令所在單元格橫…

java快速排序

package com.atguigu.java;/*** 快速排序* 通過一趟排序將待排序記錄分割成獨立的兩部分&#xff0c;其中一部分記錄的關鍵字均比另一部分關鍵字小&#xff0c;* 則分別對這兩部分繼續進行排序&#xff0c;直到整個序列有序。*/ public class QuickSort {private static void s…

網址備份

1.jstl標簽庫http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/2.tomcat服務器http://tomcat.apache.org/3.mysql架包https://mvnrepository.com/4.jqueryhttps://github.com/jquery/jquery/releases5.圖標http://icons8.com/preloaders6.jquery-formhttp://…

前端開發-熱更新原理解讀

- 一、websocket簡介- 二、熱跟新原理- 三、實例剖析- 四、總結websocket簡介 在h5推出之前&#xff0c;瀏覽器應用跟服務器端通信的機制只有http協議&#xff0c;http是一種無狀態的網絡協議&#xff0c;前端向服務器發起一個請求&#xff0c;服務器給出一次應答&#xff…

java楊輝三角

package com.atguigu.exer; /** 使用二維數組打印一個 10 行楊輝三角。【提示】1. 第一行有 1 個元素, 第 n 行有 n 個元素2. 每一行的第一個元素和最后一個元素都是 13. 從第三行開始, 對于非第一個元素和最后一個元素的元素。即&#xff1a; yanghui[i][j] yanghui[i-1][j-1…

這65條工作和成長建議,你將受用終生!

這65條工作和成長建議&#xff0c;每一條都值得我們認真思考。希望對你有啟發。 從1990年進入格力&#xff0c;董明珠已經工作了近30年。 她花了近30年的時間&#xff0c;一手把格力從一家虧損的中小企業變成全球500強&#xff0c;年銷售額超過1400億。 2004年&#xff0c;她被…

HTML5事件—visibilitychange 頁面可見性改變事件

又看到一個很有意思的HTML5事件 visibilitychange事件是瀏覽器新添加的一個事件&#xff0c;當瀏覽器的某個標簽頁切換到后臺&#xff0c;或從后臺切換到前臺時就會觸發該消息&#xff0c;現在主流的瀏覽器都支持該消息了&#xff0c;例如Chrome, Firefox, IE10等。雖然這只是一…

java回型數

import java.util.Arrays;public class hello {public static void main(String[] args) {//輸出5*5的int n 5;int [][] huizixingnew int[n][n];int minX0;//x軸最小下標int minY0;//y軸最小下標int maxXn-1;//x軸最大下標int maxYn-1;//y軸最大下標int counter0;//計數int xf…

用CSS3 vh 簡單實現DIV全屏居中

vh、vw、vmin、vmax介紹 vw&#xff1a;視窗寬度的百分比&#xff08;1vw 代表視窗的寬度為 1%&#xff09;vh&#xff1a;視窗高度的百分比vmin&#xff1a;當前 vw 和 vh 中較小的一個值vmax&#xff1a;當前 vw 和 vh 中較大的一個值 瀏覽器兼容性 &#xff08;1&#xff09…

解決360等等瀏覽器兼容模式解析不兼容代碼

之前寫的代碼不是很規范 , 在今天測試下發現360瀏覽器等等的瀏覽器使用兼容模式會有很多不兼容 , 網上了解過一下 , 說是很多瀏覽器的兼容模式可能就是為了兼容IE7之前的網站代碼 , 而非我們字面理解的兼容二字 ... OK!跑題了 ... 我的解決方案是在頁面head加<meta http…

java自定義異常報錯

public class TeamException extends Exception{static final long serialVersionUID -3387516993124229948L;public TeamException() {super();}public TeamException(String message) {super(message);} }

P多行溢出省略號的處理

因為-webkit-line-clamp: 2不兼容火狐或IE&#xff0c;采用判斷瀏覽器的方式來啟用哪個方式先判斷是什么瀏覽器 //判斷是否是谷歌瀏覽器 if (!stripos($_SERVER["HTTP_USER_AGENT"], chrome)) {$this->registerCssFile(web/css/view.css); } 行內樣式&#xff08;…

縮小窗口時CSS背景圖出現右側空白BUG的解決方法

頁面容器&#xff08;#wrap&#xff09;與頁面頭部&#xff08;#header &#xff09;為100%寬度。而內容的容器&#xff08;#page&#xff09;為固定寬度960px。瀏覽窗口縮小而小于內容層寬度時會產生寬度理解上的差異。如下圖所示窗口寬度大于內容層寬度&#xff1a; 改變瀏覽…

JAVA鏈接Mysql數據庫(一)

第一步自定義 properties 文件 userroot password12345 urljdbc:mysql://localhost:3306/test?useUnicodetrue&characterEncodingutf8 driverClasscom.mysql.jdbc.Driver第二部 創建 java 文件運行 import java.io.InputStream; import java.sql.Connection; import java…

優化器,SGD+Momentum;Adagrad;RMSProp;Adam

Optimization 隨機梯度下降&#xff08;SGD&#xff09;&#xff1a; 當損失函數在一個方向很敏感在另一個方向不敏感時&#xff0c;會產生上面的問題&#xff0c;紅色的點以“Z”字形梯度下降&#xff0c;而不是以最短距離下降&#xff1b;這種情況在高維空間更加普遍。 SGD的…

iOS開發-平臺使用TestFlight進行Beta測試

使用 TestFlight&#xff0c;你可以向測試人員發布你 App 的 prerelease 版本來收集反饋信息&#xff0c;為將來發布 App 的正式版做準備。現在 TestFlight 是一個可選功能&#xff0c;你也可以不使用它&#xff0c;而是像以往發布 App 那樣直接提交到 appStore。 TestFlight 使…

QPixmap QImage 相互轉化

QPainter p(this); QPixmap pixmap; pixmap.load("E:\\參考文件\\image\\1.jpg"); //QPixmap->QImage QImage tempImage pixmap.toImage(); p.drawImage(0,0,tempImage); QImage image; image.load("E:\\參考文件\\image\\1.jpg"); //QImage->QPixm…

java語言介紹 —(1)

1.基礎常識 軟件&#xff1a;即一系列按照特定順序組織的計算機數據和指令的集合。分為&#xff1a;系統軟件 和 應用軟件 系統軟件&#xff1a;windows , mac os , linux ,unix,android,ios,… 應用軟件&#xff1a;word ,ppt,畫圖板,… 人機交互方式&#xff1a; 圖形化界面…

微信小程序入門資源整理(熱更新)

從零開始&#xff1a;微信小程序新手入門寶典《一》 傳送門地址&#xff1a; https://segmentfault.com/a/1190000008035180 微信小程序部分資源整理 傳送門地址&#xff1a;http://blog.csdn.net/u012995964/article/details/53116477

第一個java程序helloworld —(2)

1.開發體驗——HelloWorld 1.1 編寫 創建一個java源文件&#xff1a;HelloWorld.java class HelloChina{public static void main(String[] args){System.out.println("Hello,World!");} }1.2 編譯&#xff1a; javac HelloWorld.java 1.3 運行&#xff1a; java Hel…