2014
03-23

# Three Kingdoms

Three Kingdoms is a funny game. Often Liu Bei is weak and has to run away,so in the game Liu Bei has a skill called "Dunzou". This time you are playing the role of Liu Bei.As Cao Cao’s power is so strong, there is nothing you can do but escaping. Please select an optimal path to achieve the purpose .
To simplify the problem, Liu Bei can only move in one of the four direction (up, down,right,left) each time. The map contains the following characters:
‘A’ : Representative of watchtower, which has an attack range of 2(measured by Manhattan distance),and an attack damage of 1.
‘B’ : Representative of Fort, which has an attack range of 3(measured by Manhattan distance),and an attack damage of 2.
‘C’ : Representative of Flame, which has an attack damage of 3 to those who step onto it.
‘D’ : Representative of Archer, which has anattack range of 2(measured by Manhattan distance), and an attack damage of 4.
‘E’ : Representative of Ordinary soldier, which has anattack range of 1(measured by Manhattan distance), and an attack damage of 5.
‘$’ : Representative of Liu Bei. ‘!’ : Representative of Destination. ‘#’ : Representative of obstacles ‘.’ : Representative of floor. Liu Bei can not enter watchtower, forts, Archers, ordinary soldiers,But he can step onto flame or floor. Some important rules you should note: 1. Liu Bei will not be hurt by the same thing twice.For example,if Liu Bei has been hurt by one watchtower before,then he step into the attack range of some watchtower later,he will not be hurt. 2. When Liu Bei reach the destination,you should first judge the attack damage at the destination then finish the game. 3. You needn’t judge the attack damage at the start position. Please choose a path which LiuBei would cost the least HP. 输入: In the first line there is an integer T, indicates the number of test cases.(T<=60) In each case,the first line of the input contains two integer n,m(1<=n,m<=50),reperesenting the size of map(n*m).Then follow n lines,each line contain m characters. There may be some blank lines between each case. 输出: In the first line there is an integer T, indicates the number of test cases.(T<=60) In each case,the first line of the input contains two integer n,m(1<=n,m<=50),reperesenting the size of map(n*m).Then follow n lines,each line contain m characters. There may be some blank lines between each case. 样例输入: 1 4 3 .$.
ACB
ACB
.!.

Case 1: 6

﻿﻿

已被周赛虐成挂零狗。
BFS + 优先队列 == 最短路，貌似是可以这样理解的。这样得到的结果即为花费最少的一条路。貌似初级计划里面有一个类似的题。
因为受过的伤不会再受，所以需要抽象出第三维来表示受过的哪几种伤（状压）。寒假集训的时候还给大一的选手出过这种题。。。竟然还有脸给大一的讲题。。

曼哈顿距离：在欧几里得空间的固定直角坐标系上两点所形成的线段对轴产生的投影的距离总和。

例如在平面上，坐标（x1, y1）的i点与坐标（x2, y2）的j点的曼哈顿距离为：

d(i,j)=|X1-X2|+|Y1-Y2|.

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <stack>

#define EPS (1e-6)
#define LL long long
#define ULL unsigned long long int
#define _LL __int64
#define _INF 0x3f3f3f3f
#define INF (1<<62)
#define Mod 1000000007

using namespace std;

char Map[51][51];

int hurt[51][51][5];

bool mark[51][51][33];

void Init_Hurt(int n,int m)
{
int i,j,k,l;

memset(hurt,0,sizeof(hurt));

for(i =1;i <= n; ++i)
{
for(j = 1;j <= m ; ++j)
{
if(Map[i][j] == 'A')
{
for(k = i-2;k <= i+2; ++k)
{
for(l = j-2;l <= j+2; ++l)
{
if(1 <= k && k <= n && 1 <= l && l <= m && abs(k-i)+ abs(l-j) <= 2)
{
hurt[k][l][0] = 1;
}
}
}
}
else if(Map[i][j] == 'B')
{
for(k = i-3;k <= i+3; ++k)
{
for(l = j-3;l <= j+3; ++l)
{
if(1 <= k && k <= n && 1 <= l && l <= m && abs(k-i)+ abs(l-j) <= 3)
{
hurt[k][l][1] = 2;
}
}
}
}
else if(Map[i][j] == 'C')
{
hurt[i][j][2] = 3;
}
else if(Map[i][j] == 'D')
{
for(k = i-2;k <= i+2; ++k)
{
for(l = j-2;l <= j+2; ++l)
{
if(1 <= k && k <= n && 1 <= l && l <= m && abs(k-i)+ abs(l-j) <= 2)
{
hurt[k][l][3] = 4;
}
}
}
}
else if(Map[i][j] == 'E')
{
for(k = i-1;k <= i+1; ++k)
{
for(l = j-1;l <= j+1; ++l)
{
if(1 <= k && k <= n && 1 <= l && l <= m && abs(k-i)+ abs(l-j) <= 1)
{
hurt[k][l][4] = 5;
}
}
}
}
}
}
}

struct N
{
int x,y,sta,ans;
bool operator < (const N &a) const
{
return a.ans < ans;
}
};

int jx[] = {-1, 0, 1, 0};
int jy[] = { 0, 1, 0,-1};

bool Judge(char c)
{
if(c == '$' || c == 'C' || c == '!' || c == '.') return true; return false; } void bfs(int n,int m,int s,int e) { priority_queue<N> q; N f,t; f.x = s,f.y = e,f.sta = 0,f.ans = 0; memset(mark,false,sizeof(mark)); mark[s][e][0] = true; q.push(f); while(q.empty() == false) { f = q.top(); q.pop(); if(f.x != s || f.y != e) { for(int k = 0;k < 5; ++k) { if((f.sta&(1<<k)) == 0 && hurt[f.x][f.y][k]) { f.ans += hurt[f.x][f.y][k]; f.sta += (1<<k); } } } if(Map[f.x][f.y] == '!') { printf("%d\n",f.ans); return ; } for(int i = 0;i < 4; ++i) { t.ans = f.ans; t.sta = f.sta; t.x = f.x + jx[i]; t.y = f.y + jy[i]; if(1 <= t.x && t.x <= n && 1 <= t.y && t.y <= m && mark[t.x][t.y][t.sta] == false && Judge(Map[t.x][t.y]) ) { q.push(t); mark[t.x][t.y][t.sta] = true; } } } printf("-1\n"); } void Solve(int n,int m) { int i,j; for(i = 1; i <= n; ++i) { for(j = 1;j <= m; ++j) { if(Map[i][j] == '$')
{
bfs(n,m,i,j);
return ;
}
}
}
}

int main()
{
int T,icase = 0;

int i,j,k,n,m;

scanf("%d",&T);

while(T--)
{
scanf("%d %d",&n,&m);

for(i = 1;i <= n ; ++i)
{
scanf("%*c%s",Map[i]+1);
}

Init_Hurt(n,m);

printf("Case %d: ",++icase);

Solve(n,m);

}
return 0;
}

1. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

2. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

3. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

4. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

5. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

6. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

7. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

8. 用一大把鱼线往狂奔的姑娘群中一扔，鲜美的分割肉就出炉了，在火候正好的时候，糯糯的炖上，夜晚时分，看着岛国最新的艾薇，咬一口蒸奶子，肥而不腻入口即化，美哉

9. bottes vernies blanches

I appreciate the efforts you men and women place in to share blogs on such sort of matters, it was certainly useful. Keep Posting!