HDU 1690 最短路
来源:互联网 发布:数据库高级培训 编辑:程序博客网 时间:2024/05/22 17:51
#include<stdio.h>
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
typedef __int64 ll;
#define inf 0x3f3f3f3f
//#define inf 0x7f7f7f7f7f7f7f7fLL
#define min(x,y) (x<y?x:y)
ll l1,l2,l3,l4,c1,c2,c3,c4;
int n,m;
ll x[102];
ll dist[102][102];
void floyd(){
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(dist[i][k]==inf||dist[k][j]==inf){
continue;
}
ll res=dist[i][k]+dist[k][j];
if(res<dist[i][j]){
dist[i][j]=res;
}
}
}
}
}
int main(){
int T;
scanf("%d",&T);
for(int t=1;t<=T;t++){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%I64d",&x[i]);
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
ll d=x[i]-x[j];
if(d<0){
d*=-1;
}
if(0<d&&d<=l1){
dist[i][j]=dist[j][i]=c1;
}
else if(l1<d&&d<=l2){
dist[i][j]=dist[j][i]=c2;
}
else if(l2<d&&d<=l3){
dist[i][j]=dist[j][i]=c3;
}
else if(l3<d&&d<=l4){
dist[i][j]=dist[j][i]=c4;
}
else{
dist[i][j]=dist[j][i]=inf;
}
}
}
floyd();
printf("Case %d:\n",t);
for(int i=0;i<m;i++){
int a,b;
scanf("%d%d",&a,&b);
if(dist[a][b]==inf){
printf("Station %d and station %d are not attainable.\n",a,b);
}
else{
printf("The minimum cost between station %d and station %d is %I64d.\n",a,b,dist[a][b]);
}
}
}
}
#include<string.h>
#include<queue>
#include<algorithm>
using namespace std;
typedef __int64 ll;
#define inf 0x3f3f3f3f
//#define inf 0x7f7f7f7f7f7f7f7fLL
#define min(x,y) (x<y?x:y)
ll l1,l2,l3,l4,c1,c2,c3,c4;
int n,m;
ll x[102];
ll dist[102][102];
void floyd(){
for(int k=1;k<=n;k++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(dist[i][k]==inf||dist[k][j]==inf){
continue;
}
ll res=dist[i][k]+dist[k][j];
if(res<dist[i][j]){
dist[i][j]=res;
}
}
}
}
}
int main(){
int T;
scanf("%d",&T);
for(int t=1;t<=T;t++){
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%I64d",&x[i]);
}
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
ll d=x[i]-x[j];
if(d<0){
d*=-1;
}
if(0<d&&d<=l1){
dist[i][j]=dist[j][i]=c1;
}
else if(l1<d&&d<=l2){
dist[i][j]=dist[j][i]=c2;
}
else if(l2<d&&d<=l3){
dist[i][j]=dist[j][i]=c3;
}
else if(l3<d&&d<=l4){
dist[i][j]=dist[j][i]=c4;
}
else{
dist[i][j]=dist[j][i]=inf;
}
}
}
floyd();
printf("Case %d:\n",t);
for(int i=0;i<m;i++){
int a,b;
scanf("%d%d",&a,&b);
if(dist[a][b]==inf){
printf("Station %d and station %d are not attainable.\n",a,b);
}
else{
printf("The minimum cost between station %d and station %d is %I64d.\n",a,b,dist[a][b]);
}
}
}
}
- HDU 1690 最短路
- HDU 1690 最短路 FLOYD
- hdu 1690Bus System,(最短路)
- hdu 1690 Bus System(最短路)
- hdu 1690 Bus System(最短路)
- hdu 1690 Bus System(Dijkstra最短路)
- 最短路 2544hdu
- HDU 2544 最短路
- hdu 1245 最短路
- HDU最短路总结
- hDU 最短路
- hdu 1874 (最短路)
- hdu 2112 (最短路)
- HDU-2544 最短路
- Hdu-2544 最短路
- hdu 2066 最短路
- HDU 2544 最短路
- 最短路 hdu
- C#泛型集合 using System.Collections.Generic
- Android中的Handler总结
- 正则表达式全解
- 普林斯顿大学算法第一周个人总结1
- FLASh RAM
- HDU 1690 最短路
- JAVA 删除文本文件中的空行
- strcpy函数的实现
- 用C++编写COM组件
- java.lang.NoSuchFieldError: TRACE
- java 堆栈
- ExtJS4.2学习(3)——基础知识之简单特性
- ant教程详解
- python