帮 大一学弟 AC一道题

❥题面

❥思路

每个格子都可以作为开始节点,遍历找到最大数,可以直接用优先队列去模拟,或者用dfs+回溯

❥代码
#include <iostream> #include <cstdio> #include <algorithm> #include <queue>
using namespace std; struct Node { int val,zx,zy; bool operator<(const Node&e)
const{return val < e.val;} }; int answer; int main() { int number,time;
cin>>number>>time; priority_queue<Node> ok; for(int i=1; i<=number; i++) {
for(int j=1; j<=number; j++) { int val; cin>>val; ok.push({val,i,j}); } } int
tmpx=1, tmpy=1; while(time && ok.size()) { Node cur = ok.top(); ok.pop(); int
val = cur.val, zx=cur.zx, zy=cur.zy; int get_need = abs(zx-tmpx) + abs(zy-tmpy)
+ val; if(get_need<=time) { answer += val; time -= get_need; tmpx=zx,tmpy=zy; }
else break; } cout<<answer; return 0; }

技术
今日推荐
PPT
阅读数 135
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信