<?php
header ( "Content-Type: text/plain; charset=utf-8" ) ; ?>
<?php
/* http://d...content-available-to-author-only...2.net/ */
SUBWAY => 'едешь на метро' ,
FOOT => 'идешь пешком' ,
BUS => 'едешь на автобусе'
) ;
$startPoint = 'pet' ; // Петроградская
$endPoint = 'teh' ; // Новая Голландия
'pet' => 'ст. м. Петроградская' ,
'chk' => 'ст. м. Чкаловская' ,
'gor' => 'ст. м. Горьковская' ,
'spo' => 'ст. м. Спортивная' ,
'vas' => 'ст. м. Василеостровская' ,
'kre' => 'Петропавловская крепость' ,
'let' => 'Летний сад' ,
'dvo' => 'Дворцовая площадь' ,
'isa' => 'Исакиевский собор' ,
'nov' => 'Новая Голландия' ,
'ras' => 'Дом Раскольникова' ,
'gos' => 'Гостиный Двор' ,
'sen' => 'Сенная Площадь' ,
'vla' => 'ст. м. Владимирская' ,
'vit' => 'Витебский вокзал' ,
'teh' => 'Технологический Институт'
) ;
'chk' => canGet( 10 , BUS) ,
'gor' => canGet( 3 , SUBWAY)
) ,
'pet' => canGet( 10 , BUS) ,
'spo' => canGet( 3 , SUBWAY)
) ,
'pet' => canGet( 3 , BUS) ,
'kre' => canGet( 5 , FOOT) ,
'gos' => canGet( 6 , SUBWAY)
) ,
'chk' => canGet( 3 , SUBWAY) ,
'vas' => canGet( 10 , BUS) ,
'sen' => canGet( 7 , SUBWAY)
) ,
'spo' => canGet( 10 , BUS) ,
'gos' => canGet( 7 , SUBWAY) ,
'nov' => canGet( 11 , FOOT)
) ,
'gor' => canGet( 5 , FOOT)
) ,
'dvo' => canGet( 6 , FOOT) ,
'gos' => canGet( 7 , FOOT)
) ,
'isa' => canGet( 6 , FOOT) ,
'gos' => canGet( 6 , FOOT) ,
'let' => canGet( 6 , FOOT)
) ,
'dvo' => canGet( 6 , FOOT) ,
'nov' => canGet( 5 , FOOT)
) ,
'vas' => canGet( 11 , FOOT) ,
'isa' => canGet( 5 , FOOT) ,
'ras' => canGet( 7 , BUS)
) ,
'nov' => canGet( 7 , BUS) ,
'sen' => canGet( 3 , FOOT)
) ,
'vas' => canGet( 7 , SUBWAY) ,
'sen' => canGet( 3 , SUBWAY) ,
'dvo' => canGet( 6 , FOOT) ,
'gor' => canGet( 6 , SUBWAY) ,
'let' => canGet( 7 , FOOT) ,
'vla' => canGet( 7 , FOOT)
) ,
'ras' => canGet( 3 , FOOT) ,
'spo' => canGet( 7 , SUBWAY) ,
'gos' => canGet( 3 , SUBWAY) ,
'vla' => canGet( 4 , SUBWAY) ,
'vit' => canGet( 2 , SUBWAY) ,
'teh' => canGet( 3 , SUBWAY)
) ,
'sen' => canGet( 4 , SUBWAY) ,
'gos' => canGet( 7 , FOOT) ,
'vit' => canGet( 3 , SUBWAY)
) ,
'sen' => canGet( 2 , SUBWAY) ,
'teh' => canGet( 2 , SUBWAY) ,
'vla' => canGet( 3 , SUBWAY)
) ,
'sen' => canGet( 3 , SUBWAY) ,
'vit' => canGet( 2 , SUBWAY)
)
) ;
/* Чтобы не писать много раз array('time' => ..., 'by' => ...), используем функцию.
«canGet» переводится как «можно попасть» */
function canGet( $time , $byWhat )
{
'time' => $time ,
'by' => $byWhat
) ;
}
$time = 0 ;
$lowerTime = 0 ;
function makeOneStep( $paths , $startPoint , $endPoint , $time , $lowerTime , $crossingTime , $pathDone )
{
$pathDone [ ] = $startPoint ;
if ( isset ( $paths [ $startPoint ] [ $endPoint ] ) ) { $pathDone [ ] = $endPoint ;
$c = $paths [ $startPoint ] [ $endPoint ] [ 'time' ] ;
$crossingTime [ ] = $c ;
$time += $paths [ $startPoint ] [ $endPoint ] [ 'time' ] ;
$result [ 'path' ] = $pathDone ;
$result [ 'time' ] = $time ;
$result [ 'ct' ] = $crossingTime ;
return $result ;
}
foreach ( $paths [ $startPoint ] as $stationName => $stationInfo ) {
if ( ! in_array ( $stationName , $pathDone ) ) { $time += $paths [ $startPoint ] [ $stationName ] [ 'time' ] ;
$crossingTime [ ] = $paths [ $startPoint ] [ $stationName ] [ 'time' ] ;
$newPath = makeOneStep( $paths , $stationName , $endPoint , $time , $lowerTime , $crossingTime , $pathDone ) ;
if ( $lowerTime == 0 XOR ( $time < $lowerTime ) ) {
$lowerTime = $time ;
$shortest = $newPath ;
}
}
}
$result = $shortest ;
return $result ;
}
$path = makeOneStep( $paths , $startPoint , $endPoint , $time , $lowerTime , $crossingTime , $pathDone ) ;
$text = "Маршрут построен: \n " ;
$i = 0 ;
foreach ( $path [ 'path' ] as $station ) {
if ( $i == 0 ) {
$text .= "Точка отправления: $pointNames [$station ] \n " ;
$i ++;
CONTINUE ;
}
if ( $i == count ( $path [ 'path' ] ) - 1 ) { $text .= "Конечная точка: $pointNames [$station ]. \n Затраченное время: {$path['time']} " ;
} else {
$text .= "$i $pointNames [$station ] . Необходимое время : {$path ['ct'][$i -1]}\n " ;
$i ++;
}
}
echo $text ;
PD9waHAKaGVhZGVyKCJDb250ZW50LVR5cGU6IHRleHQvcGxhaW47IGNoYXJzZXQ9dXRmLTgiKTsKPz4KCjw/cGhwCm1iX2ludGVybmFsX2VuY29kaW5nKCJVVEYtOCIpOwoKZXJyb3JfcmVwb3J0aW5nKC0xKTsKLyogaHR0cDovL2QuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLjIubmV0LyAqLwoKZGVmaW5lKCdTVUJXQVknLCAnc3ViJyk7CmRlZmluZSgnRk9PVCcsICdmb290Jyk7CmRlZmluZSgnQlVTJywgJ2J1cycpOwoKJHRyYW5zcG9ydE5hbWUgPSBhcnJheSgKICAgIFNVQldBWSA9PiAn0LXQtNC10YjRjCDQvdCwINC80LXRgtGA0L4nLAogICAgRk9PVCA9PiAn0LjQtNC10YjRjCDQv9C10YjQutC+0LwnLAogICAgQlVTID0+ICfQtdC00LXRiNGMINC90LAg0LDQstGC0L7QsdGD0YHQtScKKTsKCiRzdGFydFBvaW50ID0gJ3BldCc7IC8vINCf0LXRgtGA0L7Qs9GA0LDQtNGB0LrQsNGPCiRlbmRQb2ludCAgID0gJ3RlaCc7IC8vINCd0L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9C10YHQutC40Lkg0JjQvdGB0YLQuNGC0YPRgicKKTsKCiRwYXRocyA9IGFycmF5KAogICAgJ3BldCcgPT4gYXJyYXkoCiAgICAgICAgJ2NoaycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdnb3InID0+IGNhbkdldCgzLCBTVUJXQVkpCiAgICApLAogICAgCiAgICAnY2hrJyA9PiBhcnJheSgKICAgICAgICAncGV0JyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ3NwbycgPT4gY2FuR2V0KDMsIFNVQldBWSkKICAgICksCiAgICAKICAgICdnb3InID0+IGFycmF5KAogICAgICAgICdwZXQnID0+IGNhbkdldCgzLCBCVVMpLAogICAgICAgICdrcmUnID0+IGNhbkdldCg1LCBGT09UKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoNiwgU1VCV0FZKQogICAgKSwKICAgIAogICAgJ3NwbycgPT4gYXJyYXkoCiAgICAgICAgJ2NoaycgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ3ZhcycgPT4gY2FuR2V0KDEwLCBCVVMpLAogICAgICAgICdzZW4nID0+IGNhbkdldCg3LCBTVUJXQVkpCiAgICApLAogICAgCiAgICAndmFzJyA9PiBhcnJheSgKICAgICAgICAnc3BvJyA9PiBjYW5HZXQoMTAsIEJVUyksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ25vdicgPT4gY2FuR2V0KDExLCBGT09UKQogICAgKSwKICAgIAogICAgJ2tyZScgPT4gYXJyYXkoCiAgICAgICAgJ2dvcicgPT4gY2FuR2V0KDUsIEZPT1QpCiAgICApLAogICAgCiAgICAnbGV0JyA9PiBhcnJheSgKICAgICAgICAnZHZvJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDcsIEZPT1QpCiAgICApLAogICAgCiAgICAnZHZvJyA9PiBhcnJheSgKICAgICAgICAnaXNhJyA9PiBjYW5HZXQoNiwgRk9PVCksCiAgICAgICAgJ2dvcycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdsZXQnID0+IGNhbkdldCg2LCBGT09UKQogICAgKSwKICAgIAogICAgJ2lzYScgPT4gYXJyYXkoCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdub3YnID0+IGNhbkdldCg1LCBGT09UKQogICAgKSwKICAgIAogICAgJ25vdicgPT4gYXJyYXkoCiAgICAgICAgJ3ZhcycgPT4gY2FuR2V0KDExLCBGT09UKSwKICAgICAgICAnaXNhJyA9PiBjYW5HZXQoNSwgRk9PVCksCiAgICAgICAgJ3JhcycgPT4gY2FuR2V0KDcsIEJVUykKICAgICksCiAgICAKICAgICdyYXMnID0+IGFycmF5KAogICAgICAgICdub3YnID0+IGNhbkdldCg3LCBCVVMpLAogICAgICAgICdzZW4nID0+IGNhbkdldCgzLCBGT09UKQogICAgKSwKICAgIAogICAgJ2dvcycgPT4gYXJyYXkoCiAgICAgICAgJ3ZhcycgPT4gY2FuR2V0KDcsIFNVQldBWSksCiAgICAgICAgJ3NlbicgPT4gY2FuR2V0KDMsIFNVQldBWSksCiAgICAgICAgJ2R2bycgPT4gY2FuR2V0KDYsIEZPT1QpLAogICAgICAgICdnb3InID0+IGNhbkdldCg2LCBTVUJXQVkpLAogICAgICAgICdsZXQnID0+IGNhbkdldCg3LCBGT09UKSwKICAgICAgICAndmxhJyA9PiBjYW5HZXQoNywgRk9PVCkKICAgICksCiAgICAKICAgICdzZW4nID0+IGFycmF5KAogICAgICAgICdyYXMnID0+IGNhbkdldCgzLCBGT09UKSwKICAgICAgICAnc3BvJyA9PiBjYW5HZXQoNywgU1VCV0FZKSwKICAgICAgICAnZ29zJyA9PiBjYW5HZXQoMywgU1VCV0FZKSwKICAgICAgICAndmxhJyA9PiBjYW5HZXQoNCwgU1VCV0FZKSwKICAgICAgICAndml0JyA9PiBjYW5HZXQoMiwgU1VCV0FZ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