Henry decides to develop a web site, which will provide the service of transit search. But he can only get the transit data of Guangzhou, so his web site can only support the transit search of Guangzhou. We suppose Guangzhou is 10240 meters by 10240 meters. The coordinate of the top-left corner is (0,0). The coordinate of the bottom-right corner is (10240,10240). The X–axis is from top to bottom and the Y-axis is from left to right. At the beginning, four pictures of the size 10cm by 10 cm make up of the whole map of Guangzhou. They are numbered from 0 to 3. It is to say at the beginning the scale of the map is 1cm:512 meters. We call the four pictures are at level 1. 


When you double-click on the map using the mouse, the map will zoom in. The pictures at next level will be shown on the screen. For example, when you double-click on the above map, picture 0 will be replaced by four pictures 00, 01, 02, 03, all of whose sizes are 10 cm by 10 cm. and the scale of the map change to 1cm:256 meters. (notice that, pictures 00,01,02,03 together describe the same area as picture 0). When you continue double-click, picture 01 will be replaced by pictures 010,011,012,013, and so on. 

Now, a position’s coordinate can be given by(str, x,y). str consists of 8 characters each from 0 to 3. It describes the id of the picture which the position is located at. x and y(0cm<=x,y<=10cm) describe the position’s offset relative to the top-left corner on picture str. Notice that the X–axis is from top to bottom and the Y-axis is from left to right. 


Now, the start position and end position are given as (start, sx, sy), (end, ex, ey). And some information about the bus line will be also given. First, each bus stop will be described by (name, x, y), its name and its coordinate. Second, each bus line will be described by (name1, name2, name3…namek) which are the bus stops the bus line travels through. If the distance between the start position and end position is no more than 2000 meters, the web site will suggest walking there. Otherwise, the web site will find a bus stop whose distance is no more than 1000 meters from the start position. You can take buses to a bus stop whose distance is no more than 1000 meters from the end position. Along the way, you can change buses at any bus stop. If you can take buses according the above rules, the web site will find a route with fewest number of changing buses. If you can’t take buses according the above rules, the web site will suggest taking a taxi.

Input

The input begins with a line containing an integer T, the number of test cases. 

For each case, the first two lines describe the start position and the end position as followed. 

Start sx sy 

End ex ey 

Start and End both contain 8 characters each from 0 to 3. 0cm<=sx,sy,ex,ey<=10cm. Notice that all the numbers in the input are integers. 

The next line contains an integer n(0<n<5001), indicating the total number of bus stops in Guangzhou. The following n lines each describe a bus stop in the format: 

Name x y 

Name contains no more than 20 characters. 0<=x,y<=10240. 

Next comes an integer m(0<m<=100), indicating the number of bus lines in Guangzhou. 

Then following is the description of the m bus lines. 

Each bus line is described as followed: 



Name1 Name2 Name3 … Namek 

K(0<K<=30) is the number of bus stops along the bus line. 

Namei is the ith bus stop along the bus line. Notice that the bus line is bidirectional.

Output

(1)  If the distance between the start position and end position is no more than 2000 meters, print “walk there” in a single line. 

(2)  If you can take buses according to the above rule, print the fewest number of buses you have to take. For example, if you can take a bus directly to end position without changing bus line, print 1. 

(3)  Otherwise, print “take a taxi” in a single line.

Sample Input

3
00000000 1 1
00001000 3 3
4
a 1 1
b 20 30
c 40 50
d 100 100
2
3
a b c
3
b c d
00000000 1 1
03231130 5 5
5
a 1 1
b 1000 1000
c 3000 3000
d 3000 4000
e 4500 4000
2
3
a b c
3
c d e
00000000 1 1
03231130 5 5
4
a 1 1
b 1000 1000
c 3000 3000
d 3000 4000
2
3
a b c
3
b c d

Sample Output

walk there
2
take a taxi

题解:这个题,题目有点长。。。地图很好理解的;

如果起点和终点相距2000m以内则可以走过去;

如果起点或终点附近1000m内或者公交车到不了则打的士

其他求要坐几趟车

AC 代码为:

#include<bits/stdc++.h>

#define N 5010

#define inf 0x3f3f3f3f

using namespace std;

const int len[8] = { 5120,2560,1280,640,320,160,80,40 };

struct node {

    int x, y;

} point[N];

struct edge {

    int to, val;

} now;

string a, b;

int n, dis[N + 200];

int tot;

map<string, int> ma;

vector<edge> vec[N + 200];

double getlen(node a, node b) 

{

    return sqrt((double)(a.x - b.x)*(a.x - b.x) + (double)(a.y - b.y)*(a.y - b.y));

}

void init() 

{

    point[0].x<<=2;

    point[0].x<<=2;

    point[1].x<<=2;

    point[1].y<<=2;

    for (int i = 0; i<8; i++) 

    {

        if (a[i] == '1' || a[i] == '3') point[0].y += len[i];

        if (a[i] == '2' || a[i] == '3') point[0].x += len[i];

        if (b[i] == '1' || b[i] == '3') point[1].y += len[i];

        if (b[i] == '2' || b[i] == '3') point[1].x += len[i];

    }

    for (int i = 0; i<n + 2; i++) vec[i].clear();

    ma.clear();

}

void spfa()

{

    bool vis[N + 200];

    queue<int> q;

    memset(vis, false, sizeof(vis));

    vis[0] = true;

    while (!q.empty()) 

    {

        q.pop();

    }

    q.push(0);

    for (int i = 0; i<tot; i++) dis[i] = inf;

    dis[0] = 0;

    while (!q.empty()) 

    {

        int k = q.front(); q.pop();

        for (int i = 0; i<vec[k].size(); i++) 

        {

            if (dis[vec[k][i].to]>vec[k][i].val + dis[k]) 

            {

                dis[vec[k][i].to] = vec[k][i].val + dis[k];

                if (!vis[vec[k][i].to]) 

                {

                    vis[vec[k][i].to] = true;

                    q.push(vec[k][i].to);

                }

            }

        }

        vis[k] = false;

    }

}

bool flag1, flag2;

int main()

{

    ios::sync_with_stdio(false);

    int T, m;

    cin >> T;

    while (T--) 

    {

        cin >> a>> point[0].x >> point[0].y;

        cin >> b >> point[1].x >> point[1].y;

        cin >> n;

        init();

        flag2 = false;

        flag1 = false;

        for (int i = 2; i<n + 2; i++) 

        {

            cin >> a >> point[i].x >> point[i].y;

            ma[a] = i;

            if (getlen(point[0], point[i]) <= 1000.0) 

            {

                now.to = i;

                now.val = 0;

                vec[0].push_back(now);

                flag2 = true;

            }

            if (getlen(point[1], point[i]) <= 1000.0) 

            {

                now.to = 1;

                now.val = 0;

                vec[i].push_back(now);

                flag1 = true;

            }

        }

        flag1 = flag1 && flag2;

        flag2 = getlen(point[0], point[1]) <= 2000.0;

        cin >> m;

        int k;

        tot = n + 2;

        for (int i = 0; i<m; i++) 

        {

            vec[tot].clear();

            cin >> k;

            for (int j = 0; j<k; j++) 

            {

                cin >> b;

                int kk = ma[b];

                now.to = kk;

                now.val = 1;

                vec[tot].push_back(now);

                now.to = tot;

                vec[kk].push_back(now);

            }

            tot++;

        }

        if (flag2) cout<<"walk there"<<endl;

        else if (!flag1) cout << "take a taxi" << endl;

        else 

        {

            spfa();

            if (dis[1] == inf) cout << "take a taxi" << endl;

            else cout << (dis[1] >> 1) << endl; 

        }

    }

    return 0;

}

HDU2482-Transit search(地图还原+SPFA)的更多相关文章

  1. 百度地图api简单使用方法

    百度地图API的使用方法   百度地图API 开始学习百度地图API最简单的方式是看一个简单的示例.以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心: 1. <html&g ...

  2. 百度地图API的使用方法

    百度地图API 开始学习百度地图API最简单的方式是看一个简单的示例.以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心: 1. <html> 2. <head& ...

  3. 百度地图API开发指南

    简介什么是百度地图API? 百度地图API是一套由JavaScript语言编写的应用程序接口,它能够帮助您在网站中构建功能丰富.交互性强的地图应用.百度地图API包含了构建地图基本功能的各种接口,提供 ...

  4. WPF嵌入百度地图完整实现

    无论是做App还是web开发,很多都会用到地图功能,一般都会调用第三方的API实现地图功能!而正如国内的地图API提供方,基本上对Android.IOS和web开发提供了很完整的一套API,但是对于桌 ...

  5. 百度地图API使用介绍

    百度地图API 开始学习百度地图API最简单的方式是看一个简单的示例.以下代码创建了一个520x340大小的地图区域并以天安门作为地图的中心: 1. <html> 2. <head& ...

  6. 基于百度地图api + AngularJS 的入门地图

    转载请注明地址:http://www.cnblogs.com/enzozo/p/4368081.html 简介: 此入门地图为简易的“广州大学城”公交寻路地图,采用很少量的AngularJS进行inp ...

  7. 【百度地图API】如何制作班级地理通讯录?LBS通讯录

    原文:[百度地图API]如何制作班级地理通讯录?LBS通讯录 摘要:班级通讯录必备的功能,比如人员列表,人员地理位置标注,展示复杂信息窗口,公交和驾车等.一般班级人员都不会超过300个,因为可以高效地 ...

  8. 【百度地图API】如何制作可拖拽的沿道路测距

    原文:[百度地图API]如何制作可拖拽的沿道路测距 摘要: 地图测距,大家都会,不就map.getDistance麼.可是,这只能测任意两点的直线距离,用途不够实际啊.比如,我想测试北京天安门到北京后 ...

  9. 【百度地图API】如何制作“从这里出发”“到这里去”——公交篇

    原文:[百度地图API]如何制作"从这里出发""到这里去"--公交篇 摘要: 百度地图首页上的“从这里出发”“到这里去”,一直是开发者们很热衷的一个功能.那么, ...

随机推荐

  1. 微软的分布式应用框架 Dapr

    微服务架构已成为构建云原生应用程序的标准,微服务架构提供了令人信服的好处,包括可伸缩性,松散的服务耦合和独立部署,但是这种方法的成本很高,需要了解和熟练掌握分布式系统.为了使用所有开发人员能够使用任何 ...

  2. ActiveMQ消息队列从入门到实践(1)—JMS的概念和JMS消息模型

    1. 面向消息的中间件 1.1 什么是MOM 面向消息的中间件,Message Oriented Middleware,简称MOM,中文简称消息中间件,利用高效可靠的消息传递机制进行平台无关的数据交流 ...

  3. 在小程序中使用md5

    使用md5.js的首先你要有md5.js这个文件https://github.com/emn178/js-md5 您也可以使用Bower安装js-md5. bower install md5 对于no ...

  4. 新一代开源即时通讯应用源码定制 运营级IM聊天源码

    公司介绍:我们是专业的IM服务提供商!哇呼Chat是一款包含android客户端/ios客户端/pc客户端/WEB客户端的即时通讯系统.本系统完全自主研发,服务器端源码直接部署在客户主机.非任何第三方 ...

  5. 转:MySQL中变量的定义和变量的赋值使用(转)

    MySQL中变量的定义和变量的赋值使用(转)   说明:现在市面上定义变量的教程和书籍基本都放在存储过程上说明,但是存储过程上变量只能作用于begin...end块中,而普通的变量定义和使用都说的比较 ...

  6. python_09

    今日内容: scrapy各组件 Components: 1.引擎(EGINE) 引擎负责控制系统所有组件之间的数据流,并在某些动作发生时触发事件.有关详细信息,请参见上面的数据流部分. 2.调度器(S ...

  7. 用PHP实现一个简易版文件上传功能(超详细讲解)

    1. php简化版的图片上传(没有各种验证) 1 2 3 4 <form action="" enctype="multipart/form-data" ...

  8. 【控制系统数字仿真与CAD】实验三:离散相似法数字仿真

    一.实验目的 1. 了解离散相似法的基本原理 2. 掌握离散相似法仿真的基本过程 3. 应用离散相似法仿真非线性系统 4. MATLAB实现离散相似法的非线性系统仿真 5. 掌握SIMULINK仿真方 ...

  9. 【2018寒假集训 Day2】【动态规划】维修栅栏

    维修栅栏 问题描述: 小z最近当上了农场主!不过,还没有来得及庆祝,一件棘手的问题就摆在了小z的面前.农场的栅栏,由于年久失修,出现了多处破损.栅栏是由n块木板组成的,每块木板可能已经损坏也可能没有损 ...

  10. 如何理解Nginx, WSGI, Flask(Django)之间的关系

    如何理解Nginx, WSGI, Flask(Django)之间的关系 值得指出的是,WSGI 是一种协议,需要区分几个相近的名词: uwsgi 同 wsgi 一样也是一种协议,uWSGI服务器正是使 ...