Skip to content

Instantly share code, notes, and snippets.

@ZhanruiLiang
Created May 21, 2012 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhanruiLiang/2761005 to your computer and use it in GitHub Desktop.
Save ZhanruiLiang/2761005 to your computer and use it in GitHub Desktop.
soj1111
2
Infernus 280
Cheetah 285
PCJ600 250
Stallion 180
HotRingRacer 300
Mansion Infernus
CarShowRoom HotRingRacer
VicePort Cheetah
NorthPointMall Infernus
PayPhone PCJ600
WKCharriot Stallion
PayPhone CarShowRoom 10
PayPhone VicePort 15
VicePort WKCharriot 20
CarShowRoom Mansion 15
Mansion WKCharriot 15
Mansion NorthPointMall 5
NorthPointMall WKCharriot 5
*
Caddy 80
MrWhoopie 60
Stretch 120
CubanHermes 160
Voodoo 170
CherryPoppy MrWhoopie
Mansion Stretch
PayPhone CubanHermes
LittleHaiti Voodoo
WKCharriot Caddy
PayPhone CherryPoppy 10
CherryPoppy LittleHaiti 15
Mansion WKCharriot 20
*
#include<iostream>
#include<string>
#include<vector>
#include<sstream>
#include<deque>
#include<stack>
#include<map>
using namespace std;
const int N = 510;
const double oo = 1e10;
double adjl[N][N];
int m, n, n_vehicle, n_loca;
int vehicle_at_loca[N];
double speed[N];
//string name_vehicle[N];
//string name_loca[N];
map<string, int> id_vehicle, id_loca;
void read_data(){
int i, j;
string line;
string name, name1;
int num;
stringstream ss;
// read vehicle-speed pair
n_vehicle = 0;
while(1){
getline(cin, line);
if(line == "") break;
ss << line;
ss >> name >> num;
ss.clear();
id_vehicle[name] = n_vehicle;
speed[n_vehicle] = num;
n_vehicle++;
}
// read loca-vehicles pair
n_loca = 0;
while(1){
getline(cin, line);
if(line == "") break;
ss << line;
ss >> name >> name1;
ss.clear();
id_loca[name] = n_loca;
vehicle_at_loca[n_loca] = id_vehicle[name1];
n_loca++;
}
n = n_loca;
for(i = 0; i < n; i++){
for(int j = 0; j < n; j++)
adjl[i][j] = oo;
}
m = 0;
// read loca-loca-dist tuples
while(1){
getline(cin, line);
if(line == "*") break;
ss << line;
ss >> name >> name1 >> num;
i = id_loca[name];
j = id_loca[name1];
adjl[i][j] = adjl[j][i] =
ss.clear();
}
}
int main(){
#ifdef DEBUG
freopen("in", "r", stdin);
#endif
int tot;
string line;
cin >> tot;
getline(cin, line);
read_data(); return 0;
while(tot--){
read_data();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment