标签:报错 algo struct namespace nbsp tar targe col 分享
http://172.20.6.3/Problem_Show.asp?id=1355
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 const int maxn=210; 8 int n,m,s,t,siz; 9 struct nod{int x,y,v;}aa[maxn]; 10 struct mat{ 11 int e[maxn][maxn]; 12 mat(){memset(e,63,sizeof(e));} 13 };mat a; 14 int bb[maxn]={}; 15 mat mul(mat x,mat y){ 16 mat z; 17 for(int i=1;i<=siz;i++){ 18 for(int j=1;j<=siz;j++){ 19 for(int k=1;k<=siz;k++){ 20 z.e[i][j]=min(z.e[i][j],x.e[i][k]+y.e[k][j]); 21 } 22 } 23 }return z; 24 } 25 mat pow(mat x,int k){ 26 mat z; 27 for(int i=1;i<=siz;i++){ 28 z.e[i][i]=0; 29 } 30 while(k){ 31 if(k&1)z=mul(z,x); 32 x=mul(x,x); 33 k/=2; 34 } 35 return z; 36 } 37 int main(){ 38 scanf("%d%d%d%d",&n,&m,&s,&t); 39 for(int i=1;i<=m;i++){ 40 scanf("%d%d%d",&aa[i].v,&aa[i].x,&aa[i].y); 41 bb[2*i-1]=aa[i].x;bb[2*i]=aa[i].y; 42 }sort(bb+1,bb+1+m*2); 43 siz=unique(bb+1,bb+1+m*2)-bb-1; 44 s=lower_bound(bb+1,bb+1+siz,s)-bb; 45 t=lower_bound(bb+1,bb+1+siz,t)-bb; 46 for(int i=1;i<=m;i++){ 47 aa[i].x=lower_bound(bb+1,bb+1+siz,aa[i].x)-bb; 48 aa[i].y=lower_bound(bb+1,bb+1+siz,aa[i].y)-bb; 49 a.e[aa[i].x][aa[i].y]=aa[i].v; 50 a.e[aa[i].y][aa[i].x]=aa[i].v; 51 } 52 mat z=pow(a,n); 53 printf("%d\n",z.e[s][t]); 54 return 0; 55 }
JZYZOJ1355 [usaco2007]奶牛赛跑 矩阵乘法 离散化
标签:报错 algo struct namespace nbsp tar targe col 分享
原文地址:http://www.cnblogs.com/137shoebills/p/7787049.html