POJ 3268 Silver Cow Party

Description
One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way roads connects pairs of farms; road i requires Ti (1 ≤ Ti ≤ 100) units of time to traverse.
Each cow must walk to the party and, when the party is over, return to her farm. Each cow is lazy and thus picks an optimal route with the shortest time. A cow’s return route might be different from her original route to the party since roads are one-way.
Of all the cows, what is the longest amount of time a cow must spend walking to the party and back?


【题目分析】
巧妙地想法就是把边反过来跑一边,这要n次SPFA变成了2次。我用的方法是用和一的异或值来判断是正向与反向。


【代码】

#include <cstdio>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
int h[1001],ne[200001],to[200001],dis[1001],w[200001],en,inq[1001],ans[1001];
inline void add(int a,int b,int c)
{ne[en]=h[a];to[en]=b;w[en]=c;h[a]=en++;}
inline void SPFA(int s,int tmp)
{
    memset(dis,0x3f,sizeof dis);
    queue<int>q;
    inq[s]=1;q.push(s);dis[s]=0;
    while (!q.empty())
    {
        int x=q.front();q.pop();inq[x]=0;
        for (int i=h[x];i>=0;i=ne[i])
        {
            if (i%2==tmp) continue;
            if (dis[to[i]]>dis[x]+w[i])
            {
                dis[to[i]]=dis[x]+w[i];
                if (!inq[to[i]])
                {
                    inq[to[i]]=1;
                    q.push(to[i]);
                }
            }
        }
    }
}
int main()
{
    memset(h,-1,sizeof h);
    int n,m,k;
    cin>>n>>m>>k;
    for (int i=1;i<=m;++i)
    {
        int a,b,c;
        cin>>a>>b>>c;
        add(a,b,c);
        add(b,a,c);
    }
    SPFA(k,0);
//  for (int i=1;i<=n;++i) cout<<dis[i]<<" "; cout<<endl;
    memcpy(ans,dis,sizeof dis);
    SPFA(k,1);
//  for (int i=1;i<=n;++i) cout<<ans[i]<<" "; cout<<endl;
    int anss=0;
    for (int i=1;i<=n;++i) anss=max(anss,dis[i]+ans[i]);
    cout<<anss<<endl;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 JavaScript 编写的简单俄罗斯方块游戏(附源代码) 项目:使用 JavaScript 编写的简单俄罗斯方块游戏(附源代码) 该游戏是一个使用 HTML5 和 JavaScript 开发的简单项目。这款游戏允许玩家策略性地旋转下落的方块以清除关卡。要在此游戏中得分,您必须通过操纵方块来清除线条,使它们填满水平行。当方块掉落时,您必须 根据需要移动 和旋转它们,使它们均匀地排列在底部。 游戏制作 该游戏仅使用 HTML、CSS 和 JavaScript。谈到这款游戏的功能,这款游戏的 PC 控制也很简单。首先,您必须按空格键才能开始游戏。您可以使用箭头键来更改下落方块的位置。您可以在侧栏看到形成的分数和行。 该游戏包含大量的 javascript,用于对游戏的某些部分进行验证。 如何运行该项目? 要运行此游戏,您不需要任何类型的本地服务器,但需要浏览器。我们建议您使用现代浏览器,如 Google Chrome 和 Mozilla Firefox, 以获得更好、更优化的游戏体验。要玩游戏,首先,单击 index.html 文件在浏览器中打开游戏。 演示: 该项目为国外大神项目,可以作为毕业设计的项目,也可以作为大作业项目,不用担心代码重复,设计重复等,如果需要对项目进行修改,需要具备一定基础知识。 注意:如果装有360等杀毒软件,可能会出现误报的情况,源码本身并无病毒,使用源码时可以关闭360,或者添加信任。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值