原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2722

分析:简单最短路,读入数据烦。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#define maxn 450
#define inf 0xfffffff
using namespace std;
int blip[maxn];
int n,m;
bool vis[maxn];
struct edge
{
int to,w;
edge(int x,int y)
{
to=x;w=y;
}
};
vector<edge>e[maxn];
queue<int>q;
void spfa(const int s)
{
while(!q.empty())q.pop();
for(int i=;i<(n+)*(m+);i++)
{
vis[i]=false;
blip[i]=inf;
}
vis[s]=true;blip[s]=;
q.push(s);
while(!q.empty())
{
int u=q.front();q.pop();
for(int i=;i<e[u].size();i++)
{
if(blip[e[u][i].to]>blip[u]+e[u][i].w)
{
blip[e[u][i].to]=blip[u]+e[u][i].w;
if(!vis[e[u][i].to])
{
vis[e[u][i].to]=true;
q.push(e[u][i].to);
}
}
}
vis[u]=false;
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
if(n==||m==)break;
for(int i=;i<maxn;i++)e[i].clear();
for(int i=;i<=*n;i++)
{
int pp=m;if(i&)pp++;
for(int j=;j<pp;j++)
{
int v;char c;int tmp;
scanf("%d %c",&v,&c);
if(v!=)
{
if(c=='*'&&i%==)
{
tmp=i/*(m+)+j;
e[tmp].push_back(edge(tmp+,/v));
e[tmp+].push_back(edge(tmp,/v));
}
else if(c=='*'&&(i&))
{
tmp=i/*(m+)+j;
e[tmp].push_back(edge(tmp+m+,/v));
e[tmp+m+].push_back(edge(tmp,/v));
}
else if(c=='>')e[i/*(m+)+j].push_back(edge(i/*(m+)+j+,/v));
else if(c=='<')e[i/*(m+)+j+].push_back(edge(i/*(m+)+j,/v));
else if(c=='v')e[i/*(m+)+j].push_back(edge(i/*(m+)+j+m+,/v));
else if(c=='^')e[i/*(m+)+j+m+].push_back(edge(i/*(m+)+j,/v));
}
}
}
spfa();
if(blip[(n+)*(m+)-]==inf)cout<<"Holiday\n";
else printf("%d blips\n",blip[(n+)*(m+)-]);
}
return ;
}

HDU--2722的更多相关文章

  1. POJ 3653 &amp; ZOJ 2935 &amp; HDU 2722 Here We Go(relians) Again(最短路dijstra)

    题目链接: PKU:http://poj.org/problem? id=3653 ZJU:problemId=1934" target="_blank">http ...

  2. HDU 2722 Here We Go(relians) Again

    最短路,建图太麻烦,略过…… #include <cstdio> #include <cstring> #include <queue> const int INF ...

  3. HDU 2722 Here We Go(relians) Again (spfa)

    Here We Go(relians) Again Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/ ...

  4. HDU 2722 Here We Go(relians) Again (最短路)

    题目链接 Problem Description The Gorelians are a warlike race that travel the universe conquering new wo ...

  5. hdu 2722 Here We Go(relians) Again (最短路径)

    Here We Go(relians) Again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Jav ...

  6. HDU题解索引

    HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsu ...

  7. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  8. HDU 2112 HDU Today(Dijkstra)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 HDU Today Time Limit: 15000/5000 MS (Java/Others ...

  9. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  10. hdu 1596 find the safest road (最短路径)

    find the safest road Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. CMDBuild2.4.3安装配置

    参考文档: 官网:http://www.cmdbuild.org/en 参考:http://blog.csdn.net/shawn210/article/details/70230248 本文涉及CM ...

  2. mongodb4简明笔记

    就一数据库,掌握基本用法,其他的现学现卖就行了. 所以要把握基本套路. 创建数据库=>使用数据库=>创建集合=>使用集合=>创建文档=>使用文档 1.数据库 mongod ...

  3. Python3实现机器学习经典算法(三)ID3决策树

    一.ID3决策树概述 ID3决策树是另一种非常重要的用来处理分类问题的结构,它形似一个嵌套N层的IF…ELSE结构,但是它的判断标准不再是一个关系表达式,而是对应的模块的信息增益.它通过信息增益的大小 ...

  4. python基础-02-while格式化逻辑运算

    python其他知识目录 1.循环打印“我是小马过河” while True:    print('我是小马过河') #4.用while从一打印到10 #5.请通过循环,1 2 3 4 5 6 8 9 ...

  5. android点击事件的四种方式

    android点击事件的四种方式 第一种方式:创建内部类实现点击事件 代码如下: package com.example.dail; import android.text.TextUtils; im ...

  6. java 乐观锁 vs 悲观锁

    在数据库的锁机制中介绍过,数据库管理系统(DBMS)中的并发控制的任务是确保在多个事务同时存取数据库中同一数据时不破坏事务的隔离性和统一性以及数据库的统一性. 悲观锁其实就是 完全同步 比如 sync ...

  7. [leetcode-884-Uncommon Words from Two Sentences]

    We are given two sentences A and B.  (A sentence is a string of space separated words.  Each word co ...

  8. (转)一篇写的简明易懂的logging模块

    转:http://kenby.iteye.com/blog/1162698 一.从一个使用场景开始 开发一个日志系统, 既要把日志输出到控制台, 还要写入日志文件 import logging # 创 ...

  9. World Cup(思维+模拟)

    Description Allen wants to enter a fan zone(球迷区) that occupies a round square and has nn entrances. ...

  10. ios程序后台继续运行

    1.图标右上角显示消息个数 if ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0) { UIUserNotificati ...