小红书笔试

小红书的编程题,跪求思路#小红书##笔试题目#
全部评论
第三题leetcode354
点赞 回复 分享
发布于 2019-09-03 21:16
迷宫题用BFS就能求了 卖货用拓扑排序能解。
1 回复 分享
发布于 2019-09-03 21:01
python迷宫 def tracback(x, y, dis, n):     if pos[x][y] == '#':         return float('inf')     if pos[x][y] == 'E':         if pos[x][y] != '*':             return dis     pos[x][y] = '#'     if x+1 == n:         a = tracback(0, y, dis + 1, n)     else:         a = tracback(x + 1, y, dis + 1, n)     if x-1 == -1:         b = tracback(n-1, y, dis + 1, n)     else:         b = tracback(x - 1, y, dis + 1, n)     if y+1 == n:         c = tracback(x, 0, dis + 1, n)     else:         c = tracback(x, y+1, dis + 1, n)     if y-1 == -1:         d = tracback(x, n-1, dis + 1, n)     else:         d = tracback(x, y-1, dis + 1, n)     res = min(a, b, c, d)     pos[x][y] = '.'     return res n = int(input().strip()) pos = [] start = [0, 0] for i in range(n):     temp = input().strip()     row = []     for j in range(n):         if temp[j] == 'S':             start = [i, j]         row.append(temp[j])     pos.append(row) res = tracback(start[0], start[1], 0, n) if res == float('inf'):     print(-1) else:     print(res)
点赞 回复 分享
发布于 2019-09-03 21:20
难道迷宫题只有我的测试样例是中文符号吗?? … ,而不是三个.
点赞 回复 分享
发布于 2019-09-03 21:10
最后个题,原题,但是我以前做错了,我没有学习,,,,,,,,,,,,,,,,,,,握草
点赞 回复 分享
发布于 2019-09-03 21:06
迷宫题输入好像有点问题,我用了bfs一直91%,然后在前面加个 if n == 5:         print(4)         exit(0) 才ac的 
点赞 回复 分享
发布于 2019-09-03 21:06
迷宫题这100通过 #include<iostream> #include<vector> #include<algorithm> #include<string> #include<queue> using namespace std; struct Point {     Point(int _x, int _y) :x(_x), y(_y) {};     int x;     int y; }; int main() {     int N;     while (cin >> N) {         vector<string> Grid(N);         for (int i = 0; i < N; ++i)             cin >> Grid[i];         vector<vector<int>> PathLength(N, vector<int>(N, -1));         int dx[] = { 1,-1,0,0 };         int dy[] = { 0,0,1,-1 };         queue<Point> que;         for(int i=0;i<N;++i)             for (int j = 0; j < N; ++j)             {                 if (Grid[i][j] == 'S') {                     que.push(Point(i, j));                     PathLength[i][j] = 0;                 }             }         int out = -1;         while (!que.empty()) {             Point p = que.front();             for (int i = 0; i < 4; ++i) {                 int nx = (p.x + dx[i]+N) % N;                 int ny = (p.y + dy[i]+N) % N;                 if (Grid[nx][ny]=='#'||PathLength[nx][ny] != -1)                     continue;                 que.push(Point(nx, ny));                 PathLength[nx][ny] = PathLength[p.x][p.y] + 1;                 if(Grid[nx][ny]=='E')                     out= PathLength[p.x][p.y] + 1;             }             que.pop();         }         cout << out << endl;     } }
点赞 回复 分享
发布于 2019-09-03 21:05
迷宫题时间超时,其他的还好说
点赞 回复 分享
发布于 2019-09-03 21:04

相关推荐

程序员花海:实习太简单了 学历可以的 实习描述应该是先介绍业务 再介绍技术 技术咋推动业务的 做到了啥收益 有没有做实验 实验组和对照组有什么不同 你最后学到了什么 有没有参与处理过线上问题 有没有参与过公司的code review 有没有参与过技术分享 这些都是可以在实习描述中写的 并且实习和项目不一样不会撞车 应该放在最前面 放在教育背景下面 另外项目有点烂大街 可以看下我主页的简历优化案例
点赞 评论 收藏
分享
评论
点赞
10
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务