1 条题解
-
0
C++ :
#include <iostream> using namespace std; int n,m,p1,p2; int a[1010][1010]; bool f[1010][1010];//标记某个点是否走过 int que[1010][3]; int fx[] = {0,1,0,-1};//方向数组 int fy[] = {1,0,-1,0}; int main(){ int i,j,head = 1,tail = 1; int x,y; cin>>n>>m>>p1>>p2; for(i = 1;i <= n;i++){ for(j = 1;j <= m;j++){ cin>>a[i][j]; } } que[head][1] = p1; que[head][2] = p2; f[p1][p2] = true;//标记走过了 while(head <= tail){ for(i = 0;i < 4;i++){ x = que[head][1] + fx[i]; y = que[head][2] + fy[i]; //判断边界 if(x <= n && x >= 1 && y <= m && y >= 1 && a[x][y] <= a[p1][p2] && f[x][y] == false){ tail++; que[tail][1] = x; que[tail][2] = y; f[x][y] = true;//标记走过了 } } head++;//统计下一个点的可行路径 } cout<<tail<<endl; }
- 1
信息
- ID
- 423
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者