简单题,,,
#include "string"
#include "iostream"
#include "cstdio"
#include "cmath"
#include "set"
#include "queue"
#include "vector"
#include "cctype"
#include "sstream"
#include "cstdlib"
#include "cstring"
#include "stack"
#include "ctime"
#include "algorithm"
#define pa pair<int,int>
#define Pi M_PI
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long LL;
#define INF 2<<20
const int M=55;
char mp[205][205];
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int vis[205][205];
int res[201][201];
int n,m;
struct node
{
int x;
int y;
int step;
}st,sd;
bool judge(int x, int y)
{
if(x<0||x>=n||y<0||y>=m||vis[x][y] == 1 || mp[x][y] == '#')
return false;
return true;
}
void bfs(int a,int b)
{
queue<node>q;
node ss;
//ss.x=0;
// ss.y=0;
memset(vis,0,sizeof(vis));
//vis[a][b]=1;
q.push((node){a,b,0});
while(!q.empty())
{
// q.pop();
st=q.front();
q.pop();
//printf("(%d, %d)\n",st.x,st.y);
if(mp[st.x][st.y]=='@')
{
res[st.x][st.y]+=st.step;
}
for(int i=0;i<4;++i)
{
int xx=st.x+dir[i][0];
int yy=st.y+dir[i][1];
if(judge(xx,yy))
{
// printf("(%d, %d)\n",xx,yy);
// sd.x=xx;
// sd.y=yy;
vis[xx][yy]=1;
q.push((node){xx,yy,st.step+1});
}
}
}
return ;
}
//void print(int x,int y)
//{
// if(!x&& !y)
// {
// printf("(0, 0)\n");
// return ;
// }
//
//
// for(int i=0;i<4;++i)
// {
// int xx=x+dir[i][0];
// int yy=y+dir[i][1];
// if(xx>=0 &&xx<5 &&yy>=0&&yy<5 &&vis[xx][yy]==vis[x][y]-1)
// {
// print(xx,yy);
// printf("(%d, %d)\n",x,y);
// return ;
// }
//
// }
//
//
//}
int main()
{
int s1x,s1y,s2x,s2y;
while(scanf("%d %d", &n, &m)!=EOF)
{
for(int i=0; i<n; i++)
{
scanf("%s", mp[i]);
for(int j=0; j<m; j++)
{
if(mp[i][j] == 'Y')
{
s1x = i;
s1y = j;
}
if(mp[i][j] == 'M')
{
s2x = i;
s2y = j;
}
}
}
memset(res, 0, sizeof(res));
bfs(s1x, s1y);
bfs(s2x, s2y);
int ans = INF;
for(int i=0;i<n;i++)
for(int j=0; j<m; j++)
{
if(mp[i][j] == '@' && res[i][j] != 0)
{
ans = min(ans, res[i][j]);
}
}
cout<<ans*11<<endl;
}
return 0;
}

本文深入探讨了C++在游戏开发领域的应用,从基础语法、内存管理到高级特性如模板、STL容器等进行了详细解析。通过实践案例,读者将学会如何使用C++高效地创建游戏逻辑、优化性能并实现复杂的游戏功能。
319

被折叠的 条评论
为什么被折叠?



