HDUOJ 1428
漫步校园
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5161 Accepted Submission(s): 1610
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 #include <cmath> 6 #include <queue> 7 8 using namespace std; 9 10 const int INF = 0x3f3f3f3f;//无穷大 11 const int maxn = 51; 12 13 int go[4][2] = { 1,0,-1,0,0,1,0,-1 };//方向 14 struct node 15 { 16 int x, y; 17 }; 18 19 int board[maxn][maxn];//记录位置(i,j)的值 20 int dis[maxn][maxn];//位置(i,j)所经历的最短路 21 int vis[maxn][maxn], n;//记录是否走过 22 23 bool operator < (const node &t1, const node &t2) 24 { 25 return dis[t1.x][t1.y] > dis[t2.x][t2.y]; 26 }//重载了比较运算符,用于 27 28 long long num[maxn][maxn];//注意数据范围 29 30 void bfs() 31 { 32 int i; 33 priority_queue<node> q;//定义一个优先队列 34 node now, next;//动态储存现在所在位置和下一步的位置对应的值 35 36 now.x = n; 37 now.y = n;//重点,从重点开始搜索 38 39 q.push(now); 40 memset(vis, 0, sizeof(vis));//根据求最小的决策,初始化为0 41 vis[n][n] = 1;//搜索开始 42 while (!q.empty())//搜索持续到队列为空 43 { 44 now = q.top(); 45 q.pop(); 46 for (i = 0; i <= 3; i++) 47 { 48 next.x = now.x + go[i][0]; 49 next.y = now.y + go[i][1]; 50 if (next.x >= 1 && next.x <= n && next.y >= 1 && next.y <= n && dis[next.x][next.y] > dis[now.x][now.y]) 51 //加上计数数组累加的条件 52 { 53 num[next.x][next.y] += num[now.x][now.y];//记录最短路的数量 54 if (!vis[next.x][next.y] && dis[next.x][next.y] >= dis[now.x][now.y] + board[next.x][next.y]) 55 { 56 dis[next.x][next.y] = dis[now.x][now.y] + board[next.x][next.y]; 57 vis[next.x][next.y] = 1;//将next标记为已访问 58 q.push(next);//更新队列 59 } 60 } 61 } 62 } 63 } 64 65 int main() 66 { 67 int i, j; 68 while (~scanf_s("%d", &n)) 69 { 70 memset(dis, 0x3f3f, sizeof(dis)); 71 memset(num, 0, sizeof(num)); 72 num[n][n] = 1; 73 74 for (i = 1; i <= n; i++) 75 for (j = 1; j <= n; j++) 76 scanf_s("%d", &board[i][j]); 77 78 dis[n][n] = board[n][n]; 79 80 bfs(); 81 82 printf("%I64d\n", num[1][1]);//long long 类型对应的格式字符 83 } 84 return 0; 85 }
转载于:https://www.cnblogs.com/CofJus/p/10028815.html
HDUOJ 1428相关推荐
- HDUOJ 1060 Leftmost Digit
问题:求x^x的最高位 思路: 假设a = x^x,对10求对数有log(a) = x * log(x) = b.cd,其中b表示指数的最大表示,10^(.cd)就是底 具体代码参考: https:/ ...
- HDUOJ 2059 龟兔赛跑——
HDUOJ 2059 龟兔赛跑 Description 据说在很久很久以前,可怜的兔子经历了人生中最大的打击――赛跑输给乌龟后,心中郁闷,发誓要报仇雪恨,于是躲进了杭州下沙某农业园卧薪尝胆潜心修炼,终 ...
- HDUOJ 1847 Good Luck in CET-4 Everybody!
HDUOJ 1847 Good Luck in CET-4 Everybody! Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧张得连短学期的ACM都 ...
- HDUOJ 4513 吉哥系列故事——完美队形II
HDUOJ 4513 吉哥系列故事--完美队形II Problem Description 吉哥又想出了一个新的完美队形游戏! 假设有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] - ...
- HDUOJ 1069 Monkey and Banana
HDUOJ 1069 Monkey and Banana 题目链接 Problem Description A group of researchers are designing an experi ...
- HDUOJ 6441 Find Integer
HDUOJ 6441 Find Integer 题目链接 Problem Description people in USSS love math very much, and there is a ...
- HDUOJ 2859 Phalanx
HDUOJ 2859 Phalanx 题目链接 Problem Description Today is army day, but the servicemen are busy with the ...
- HDUOJ 6608 Fansblog
HDUOJ 6608 Fansblog 题目链接 Problem Description Farmer John keeps a website called 'FansBlog' .Everyday ...
- HDUOJ 2955 Robberies
HDUOJ 2955 Robberies 题目链接 Problem Description The aspiring Roy the Robber has seen a lot of American ...
最新文章
- numpy之argmax()函数
- SAP RETAIL 商品LISTING方法之一
- 数据结构与算法 -- 队列 ADT
- clover configurator_枯木逢春,用Clover让老电脑从NVME SSD启动 再用叁年没问题
- JavaScript学习笔记04【高级——DOM和事件的简单学习、BOM对象】
- R语言学习(10)获取数据
- 3G-SDI光端机产品技术参数规格及产品应用领域
- 繁华模拟赛 ljw分雕塑
- 使用dotMemory Unit发现并修复内存问题
- 计算机组成原理笔记(王道考研) 第一章:计算机系统概述
- 小鸡模拟器android怎么玩,小鸡模拟器使用常见问题解决办法_模拟器使用FAQ_3DM手游...
- qt感叹号_QT使用教程(四)之初体验
- Form_Load():不要甩锅给我
- 12项信息安全标准发布 为解决车联网行业“顽疾”提供可靠指导
- 【性能测试】性能测试的概念和术语介绍 性能测试分类(了解每种测试的目的)
- 透视映客半年报:亏损背后的长期价值
- TIB自动化测试快讯 -- 自动化测试空间一周精选(2012-2-6)
- 2022年全球市场紧急出口装置总体规模、主要生产商、主要地区、产品和应用细分研究报告
- 微信小程序view下的字体居中显示
- python调用摄像头做监控_《自拍教程68》Python + ffmpeg调用摄像头,实现自动化监控录像...