第七届ccf认证第四题 自己写的错误答案



#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<cstring>
using namespace std;
#define N  50000
int dp[101][101][2];
int a[101][101];
int vis[101][101];
int d[4][2] = { { 1, 0 }, { 0, 1 }, { 0, -1 }, { -1, 0 } };
int n, m, t;
bool check(int i, int j)
{
if (i <= n &&j <= m && i > 0 && j > 0)
return true;
return false;
}
bool f(int i, int j,int step)
{
if (a[i][j] == 0)return true;
else if (a[i][j] == 1 && (step < dp[i][j][0] || dp[i][j][1] < step))
return   true;
else return false;
}
struct node
{
int x;
int y;
int step;
};
queue<node> qq;
void  bfs()
{
//if (qq.empty())
while (!qq.empty())qq.pop();
node q, p;
q.x = 1;
q.y = 1;
q.step = 0;
qq.push(q);
int x, y;
while (!qq.empty())
{
q = qq.front();
vis[q.x][q.y] = q.step;
qq.pop();
if (q.x == n && q.y == m)
{
cout << q.step << endl;
return;
}
for (int i = 0; i < 4; i++)
{
x=q.x + d[i][0];
y = q.y + d[i][1];
if (check(x, y) && q.step + 1 > vis[x][y]&& f(x,y,q.step+1))
{
p.x = x;
p.y = y;
p.step = q.step +1;
qq.push(p);
}
}


}


return;
}
int main()
{
int x, y, c, d;
while (cin >> n >> m >> t)
{
memset(vis, 0, sizeof(vis));
memset(a, 0, sizeof(a));
for (int i = 0; i < t; i++)
{
cin >> x >> y >> c >> d;
a[x][y] = 1;
dp[x][y][0] = c;
dp[x][y][1] = d;

}
bfs();


}
return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值