抓住那头牛:利用广度优先算法(队列+访问标记) 解题思路:队列(两个平行数组一个是在队列中的位置以及它此时的步数)访问标记(避免访问过的数组再次访问无用因为它访问过它后面的路径就重复了)注意事项:参考代码:#include#defineN200001intbfs(intn, 题解列表 2025年12月21日 0 点赞 0 评论 303 浏览 评分:0.0
3048: 抓住那头牛 解题思路:广度优先算法,使用队列的结构注意事项:注意更新状态数组v[MAX_POS+1]参考代码:#include#include#defineQUEUE_SIZE200000#defineMAX_POS100000typedefstruct{intpos, 题解列表 2025年12月11日 0 点赞 0 评论 288 浏览 评分:0.0
抓住那头牛! 双向BFS #双向BFS######更小的时间复杂度,更少的栈空间,更多的代码######tip:小题大做``````cpp#include#defineULLunsignedlonglong#defineLLlonglong#definePIIpairusingnamespacestd;constintN=3* 题解列表 2024年09月12日 0 点赞 1 评论 525 浏览 评分:9.9
3048: 抓住那头牛 摘要:解题思路: BFS: 三种移动方向 + 1, - 1, 2 * x注意事项:参考代码:#include<iostream> #include<cstring> using namespace st…… 题解列表 2024年04月08日 1 点赞 0 评论 764 浏览 评分:9.9
抓住那头牛(python) 摘要:解题思路:注意事项:参考代码:def catchCow(n, k): if n == k: # 如果农夫和牛的位置相等,那么花费时间为0 return 0 visited …… 题解列表 2024年01月04日 0 点赞 0 评论 539 浏览 评分:0.0
3048: 抓住那头牛 摘要:```cpp #include using namespace std; int n,k; int dfs(int t) { if(t>n>>k; int s=0; …… 题解列表 2023年04月04日 0 点赞 0 评论 899 浏览 评分:9.9
抓住那头牛(广搜) 摘要:解题思路:利用广搜注意事项:参考代码://利用广度优先搜索 //利用广度优先搜索 #include <iostream> #include <queue> using namespace s…… 题解列表 2023年03月31日 1 点赞 0 评论 1042 浏览 评分:9.9
dfs+贪心解法 摘要:解题思路:注意事项:参考代码:#include<iostream>using namespace std;int n,k;int dfs(int t){ if(t<=n) { …… 题解列表 2023年03月25日 0 点赞 0 评论 580 浏览 评分:0.0
抓住那头牛,深搜 ```#includeusingnamespacestd;intn,k;//深度搜索intdfs(intt)//n到t的时间{//不能乘车if(t>n>>k;ints=0;if(n==0)//特判一下,如果n==0,2x没有用,抓牛过程中无论如何至少会往前走一步{n++;s++;}s+=dfs(k); 题解列表 2023年03月20日 0 点赞 0 评论 794 浏览 评分:9.9