Transit search
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 849 Accepted Submission(s): 323
Problem Description
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.
![](https://i-blog.csdnimg.cn/blog_migrate/c6150603b2fec14a0a08adcbfcdff0ec.jpeg)
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.
![](https://i-blog.csdnimg.cn/blog_migrate/e7e4b6a349eb43b1df08f4e8cfde6c76.jpeg)
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:
K
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.
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:
K
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.
(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
PS:怪我英语太差了,看别人的博客才看懂题意,而且起点和终点的坐标怎么求的还是没有搞懂。
题意: 1)如果起点和终点相距2000m以内则可以走过去;
2)如果起点或终点附近1000m内或者公交车到不了则打的士
3)其他求要坐几趟车
思路:想了很久如何表现线路,然后想到把线路当成一个点,每个站都与该点连双向箭头。
1 #include <iostream> 2 #include <cstring> 3 #include <queue> 4 #include <vector> 5 #include <map> 6 #include <cmath> 7 #define N 5010 8 #define inf 0x3fffffff 9 using namespace std; 10 const int len[8]={5120,2560,1280,640,320,160,80,40}; 11 struct node{ 12 int x,y; 13 }point[N]; 14 struct edge{ 15 int to,val; 16 }now; 17 string a,b; 18 int n,d[N+200]; 19 int tot; 20 map<string,int> ma; 21 vector<edge> mapp[N+200]; 22 double getlen(node a,node b){ 23 return sqrt((double)(a.x-b.x)*(a.x-b.x)+(double)(a.y-b.y)*(a.y-b.y)); 24 } 25 void init(){ 26 point[0].x=point[0].x<<2; 27 point[0].y=point[0].y<<2; 28 point[1].x=point[1].x<<2; 29 point[1].y=point[1].y<<2; 30 for(int i=0;i<8;i++){ 31 if(a[i]=='1'||a[i]=='3'){ 32 point[0].y+=len[i]; 33 } 34 if(a[i]=='2'||a[i]=='3'){ 35 point[0].x+=len[i]; 36 } 37 } 38 for(int i=0;i<8;i++){ 39 if(b[i]=='1'||b[i]=='3'){ 40 point[1].y+=len[i]; 41 } 42 if(b[i]=='2'||b[i]=='3'){ 43 point[1].x+=len[i]; 44 } 45 } 46 for(int i=0;i<n+2;i++){ 47 mapp[i].clear(); 48 } 49 ma.clear(); 50 } 51 52 void spfa(){ 53 bool vis[N+200]; 54 queue<int> q; 55 memset(vis,false,sizeof(vis)); 56 vis[0]=true; 57 while(!q.empty()){ 58 q.pop(); 59 } 60 q.push(0); 61 for(int i=0;i<tot;i++){ 62 d[i]=inf; 63 } 64 d[0]=0;//这两个居然放反了,wa了一次 65 while(!q.empty()){ 66 int k=q.front(); 67 q.pop(); 68 for(int i=0;i<mapp[k].size();i++){ 69 if(d[mapp[k][i].to]>mapp[k][i].val+d[k]){ 70 d[mapp[k][i].to]=mapp[k][i].val+d[k]; 71 if(!vis[mapp[k][i].to]){ 72 vis[mapp[k][i].to]=true; 73 q.push(mapp[k][i].to); 74 } 75 } 76 } 77 vis[k]=false; 78 } 79 } 80 bool hashline,tooshort; 81 int main(){ 82 cin.sync_with_stdio(false); 83 int T,m; 84 cin>>T; 85 while(T--){ 86 cin>>a>>point[0].x>>point[0].y; 87 cin>>b>>point[1].x>>point[1].y; 88 cin>>n; 89 init(); 90 tooshort=false; 91 hashline=false; 92 for(int i=2;i<n+2;i++){ 93 cin>>a>>point[i].x>>point[i].y; 94 ma[a]=i; 95 if(getlen(point[0],point[i])<=1000.0){ 96 now.to=i; 97 now.val=0; 98 mapp[0].push_back(now); 99 tooshort=true; 100 } 101 if(getlen(point[1],point[i])<=1000.0){ 102 now.to=1; 103 now.val=0; 104 mapp[i].push_back(now); 105 hashline=true; 106 } 107 } 108 hashline=hashline&&tooshort; 109 tooshort=getlen(point[0],point[1])<=2000.0; 110 cin>>m; 111 int k; 112 tot=n+2; 113 for(int i=0;i<m;i++){ 114 mapp[tot].clear();// 115 cin>>k; 116 for(int j=0;j<k;j++){ 117 cin>>b; 118 int kk=ma[b]; 119 now.to=kk; 120 now.val=1; 121 mapp[tot].push_back(now); 122 now.to=tot; 123 mapp[kk].push_back(now); 124 } 125 tot++; 126 } 127 if(tooshort){ 128 cout<<"walk there"<<endl; 129 } 130 else if(!hashline){ 131 cout<<"take a taxi"<<endl; 132 } 133 else{ 134 spfa(); 135 if(d[1]==inf){ 136 cout<<"take a taxi"<<endl; 137 } 138 else{ 139 cout<<(d[1]>>1)<<endl; 140 } 141 } 142 } 143 return 0; 144 }
2017-01-26 21:48:47