HDU 2722 Here We Go(relians) Again (输入处理恶心)(二)

2014-11-24 09:46:35 · 作者: · 浏览: 1
ow of east-west streets, then north-south streets, and so on, until the southernmost row of east-west streets. Speed limits and directions of travel are specified in order from west to east, and each consists of an integer from 0 to 9 indicating speed limit, and a symbol indicating which direction traffic may flow. A zero speed limit means the road is closed. All digits and symbols are delimited by a single space. For east-west streets, the symbol will be an asterisk '*' which indicates travel is allowed in both directions, a less-than symbol '<' which indicates travel is allowed only in an east-to-west direction, or a greater-than symbol '>' which indicates travel is allowed only in a west-to-east direction. For north-south streets, an asterisk again indicates travel is allowed in either direction, a lowercase "vee" character 'v' indicates travel is allowed only in a north-to-south directions, and a caret symbol '^' indicates travel is allowed only in a south-to-north direction. A zero speed, indicating a closed road, is always followed by an asterisk. Input cities continue in this manner until a value of zero is specified for both the vertical and horizontal dimensions.

Output
For each input scenario, output a line specifying the integer number of blips of the shortest route, a space, and then the word "blips". For scenarios which have no route, output a line with the word "Holiday".

Sample Input
2 2
9 * 9 *
6 v 0 * 8 v
3 * 7 *
3 * 6 v 3 *
4 * 8 *
2 2
9 * 9 *
6 v 9 * 8 v
3 * 7 *
3 * 6 v 3 *
4 * 8 *
2 2
9 * 9 *
6 ^ 0 * 8 ^
3 * 7 *
3 * 6 ^ 3 *
4 * 8 *
0 0

Sample Output
1715 blips
1295 blips
Holiday


题目大意:
题目读得有点恶心。n*m大小的矩形,起点在矩形的左上角, 终点在右下角,里面一个小矩形代表一个街区(block)。每个小矩形的边长都是2520, 小矩形的边有一个速度限制,范围是0~9, 如果是0表示这条边不能行驶。
关于输入部分,也确实够恶心的,由上到下,从左到右,按照上图的对应的位置方式给出数据, 每一条边是 "数字"+“空格”+“符号”的形式, 数字表示这条边的限速, 符号表示这条路是单向(还分东西, 南北)的还是双向的。


分析与总结:
这题的关键在于读题以及处理输入, 建完图之后随便用哪个最短路算法都行,爱啥啥。

代码:
[cpp]
#include
#include
#include
#include
#include
using namespace std;

typedef pairpii;
const int INF = 0x7fffffff;
const int VN = 445;
const int EN = VN*VN/2;

struct Edge{
int v, next, w;
}E[EN];

int n;
int m;
int vn;
int size;
int head[VN];
int d[VN];

void addEdge(int u,int v,int w){
E[size].v=v;
E[size].w=w;
E[size].next=head[u];
head[u]=size++;
}
void init(){
vn=(m+1)*(n+1);
size=0;
memset(head, -1, sizeof(head));
}

void Dijkstra(int src){
for(int i=1; i<=vn; ++i)d[i]=INF;
d[src]=0;
priority_queue,greater >q;
q.push(make_pair(d[src],src));
while(!q.empty()){
pii x = q.top(); q.pop();
int u=x.second;
if(d[u]!=x.first)continue;
for(int e=head[u]; e!=-1; e=E[e].next){
int tmp=d[u]+E[e].w;
if(d[E[e].v] > tmp){
d[E[e].v] = tmp;
q.push(make_pair(tmp,E[e].v));
}
}
}
}


int main(){
char str[100];
int u,v,w;
while(~scanf("%d%d%*c",&n,&m)&&n+m){
// input
init();
for(int i=1; i<=n*2+1; ++i){
gets(str);
int len=strlen(str);
if(i&1){
for(int j=0,k=1; j u=(m+1)*(i/2)+k;
w = str[j]-'0';
if(w==0)continue;
if(str[j+2]=='*'){
addEdge(u,u+1,2520/w);
addEdge(u+1,u,2520/w);
}
else if(str[j+2]=='<'){
addEdge(u+1,u,2520/w);
}
else{
addEdg