您当前的位置: 首页 >  游戏

钟钟终

暂无认证

  • 0浏览

    0关注

    233博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

P4554 小明的游戏,P1744 采购特价商品(spfa)

钟钟终 发布时间:2022-02-20 22:09:05 ,浏览量:0

https://www.luogu.com.cn/problem/P4554 P4554 小明的游戏 spfa 从二维表中建图,本题根据题意若相邻的符号相同则赋值为0,不同则赋值为1,利用spfa求最短路

#include 
#define y1 y11
using namespace std;
const int maxn=6e6+5;
const int inf=0x3f3f3f3f;
char mp[505][505];
int n,m,head[maxn],cnt,x1,y1,x2,y2,dist[maxn];
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
bool vis[maxn];
struct node
{
    int  to,nxt,dis;
}e[maxn];

void add(int from,int to,int dis)
{
    e[++cnt].to=to;
    e[cnt].dis=dis;
    e[cnt].nxt=head[from];
    head[from]=cnt;
}
queueq;
void spfa(int u)
{
    memset(dist,inf,sizeof(dist));
    dist[u]=0;
    q.push(u);
    vis[u]=1;
    while(!q.empty())
    {
        int x=q.front();q.pop();
        vis[x]=0;
        for(int i=head[x];~i;i=e[i].nxt)
        {
            int y=e[i].to;
            if(dist[y]>dist[x]+e[i].dis)
            {
                dist[y]=dist[x]+e[i].dis;
                if(!vis[y])
                {
                    vis[y]=1;q.push(y);
                }
            }
        }
    }
}
int main()
{
    while(scanf("%d%d",&n,&m)&&n&&m)
    {
        memset(head,-1,sizeof(head));
        memset(vis,0,sizeof(vis));
        for(int i=1;imp[i][j];
        for(int i=1;i            
关注
打赏
1664378814
查看更多评论
0.0391s