hdu 1690 构图后Floyd 数据很大
2015-06-21 11:35
232 查看
WA了好多次... 这题要用long long 而且INF要设大一点
Sample Input
2 //T
1 2 3 4 1 3 5 7 //L1-L4 C1-C4 距离和花费
4 2 //结点数 询问次数
1 //结点的横坐标
2
3
4
1 4 //起点 终点
4 1
1 2 3 4 1 3 5 7
4 1
1
2
3
10
1 4
Sample Output
Case 1:
The minimum cost between station 1 and station 4 is 3.
The minimum cost between station 4 and station 1 is 3.
Case 2:
Station 1 and station 4 are not attainable.
# include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # include <queue> # define LL long long using namespace std ; const LL INF=0x7f7f7f7f7f7f7f7fLL; const int MAXN=210; LL L[10] ; LL C[10] ; LL x[MAXN] ; LL dis[MAXN][MAXN]; int n ; void floyed()//节点从1~n编号 { int i,j,k; for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(dis[i][k]+dis[k][j] < dis[i][j] && dis[i][k] != INF && dis[k][j] != INF) dis[i][j]=dis[i][k]+dis[k][j]; } LL Cost(LL d) { if (d < 0) d *= -1 ; if (d > 0 && d<= L[1]) return C[1] ; if (d > L[1] && d<= L[2]) return C[2] ; if (d > L[2] && d<= L[3]) return C[3] ; if (d > L[3] && d<= L[4]) return C[4] ; return INF ; } int main () { // freopen("in.txt","r",stdin) ; int cnt ; int T ; cin>>T ; int Case = 0 ; while (T--) { Case++ ; cout<<"Case "<<Case<<":"<<endl ; int i , j ; LL w ; for (i = 1 ; i <= 4 ; i++) cin>>L[i]; for (i = 1 ; i <= 4 ; i++) cin>>C[i]; cin>>n>>cnt ; for (i = 1 ; i <= n ; i++) cin>>x[i]; for (i = 1 ; i <= n ; i++) for (j = 1 ; j <= n ; j++) { if(i==j)dis[i][j]=0; else dis[i][j]=INF; } for (i = 1 ; i <= n ; i++) for (j = i+1 ; j <= n ; j++) { LL d = x[i] - x[j] ; w = Cost(d) ; dis[i][j] = w ; dis[j][i] = w ; } floyed() ; int u , v ; while(cnt--) { cin>>u>>v ; if (dis[u][v] != INF) cout<<"The minimum cost between station "<<u<<" and station "<<v<<" is "<<dis[u][v]<<"."<<endl ; else cout<<"Station "<<u<<" and station "<<v<<" are not attainable."<<endl ; } } return 0 ; }View Code
相关文章推荐
- swift runtime type
- 二进制转十进制快速方法
- Android NDK之环境配置及HelloJni
- 冒泡算法 SAS & Python
- SQLHelper重构
- [Poj 2387][Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
- 全球免费网上图书馆
- iOS UIView
- C#线程
- swift optional chaining
- 信息条目评论回复数据表
- 僵尸进程
- Android常用框架 1-40
- 记一次"诡异"的mongodb进程退出事件
- 最简单 的入门且最直观的Makefile和.so文件编译链接使用方法
- 五种比较高效常用的排序算法
- cin.getline()与getline()
- 第二篇 学习OpenCV之视频播放
- DFS应用:图的拓扑排序以及Kosaraju强连通分量算法
- 真正的人工智能离我们有多远