求解释!!!zoj3532 ZOJ Monthly, September 2011
来源:互联网 发布:显示自己是阿里云的ip 编辑:程序博客网 时间:2024/05/01 12:17
此题一直WA,此为WA的代码,哪位神牛级的人物帮我解答一下,在下不胜感激!!!!
#include <algorithm>#include <iostream>#include <string.h>#include <stdio.h>#include <math.h>#include <map>#include <vector>#include <queue>#include <stack>using namespace std;const int N=1150;int inf=1000000000;map<string ,int >mp;int p,n,k;int temp[N];int num=0;int g[N][N];int dist[N];bool f[N];void init(){ mp.clear(); int i,j; for(i=0; i<N; i++) { for(j=0; j<N; j++) g[i][j]=inf; } num=0;}void dij(int s){ memset(f,0,sizeof(f)); fill(dist, dist + num, inf); int i,j; for(i=0; i<num; i++) { dist[i]=g[s][i]; } f[s]=1; //path[0]=-1; for(i=0; i<num-1; i++) { int minmum=inf; int v; for(j=0; j<num; j++) { if(!f[j]&&dist[j]<minmum) { minmum=dist[j]; v=j; } } f[v]=1; for(j=0; j<num; j++) { if(!f[j]&&g[v][j]!=inf&&dist[j]>dist[v]+g[v][j]) { dist[j]=g[v][j]+dist[v]; } } }}int main(){ int case22=1; while(scanf("%d%d",&p,&n)!=EOF) { if(p==0&&n==0)break; int i,j,ca; init(); for(ca=0; ca<p; ca++) { memset(temp,-1,sizeof(temp)); int to=0; scanf("%d ",&k); char str[500]; gets(str); int dot=0; string ss=""; for(i=0; i<500&&str[i]!='\0'; i++) { //cout<<str[i]<<endl; if(str[i]==':') { if(!mp.count(ss)) { mp.insert(pair<string ,int>(ss,num++)); temp[to++]=num-1; } else temp[to++]=mp.find(ss)->second; ss=""; i++; break; } if(str[i]==',') { if(dot%2==1) { if(!mp.count(ss)) { mp.insert(pair<string ,int>(ss,num++)); temp[to++]=num-1; } else temp[to++]=mp.find(ss)->second; ss=""; i++; } else ss+=str[i]; dot++; } else { ss+=str[i]; } } for(i=0; i<to; i++) { for(j=i+1; j<to; j++) { g[temp[i]][temp[j]]=min(g[temp[i]][temp[j]],k); g[temp[j]][temp[i]]=min(g[temp[j]][temp[i]],k); } } } printf("Database %d\n",case22++); for(i=0; i<n; i++) { char s[50]; gets(s); int tt=mp.find(s)->second; if(!mp.count("Kevin, Bacon"))printf("%s: infinity\n",s); else {dij(mp.find("Kevin, Bacon")->second); if(dist[tt]==inf)printf("%s: infinity\n",s); else printf("%s: %d\n",s,dist[tt]);} } cout<<endl; } return 0;}/*3 33 John, Belushi, Karen, Allen, Kevin, Bacon: Animal House1 Tom, Hulce, Karen, Allen: Starting Over1 Hill, Ken, Bob, Stock: kick the ballJohn, BelushiTom, HulceBob, Stock*/
- 求解释!!!zoj3532 ZOJ Monthly, September 2011
- ZOJ Monthly, September 2012
- ZOJ Monthly, September 2011(2014省赛练习)
- ZOJ Monthly, September 2012部分题目总结
- ZOJ Monthly, September 2003【部分题解】
- ZOJ 3534 Move the Mouse I (ZOJ Monthly, September 2011 F题)
- ZOJ 3892 Available Computation Sequence(ZOJ Monthly, September 2015)
- ZOJ Monthly, May 2011
- [ZOJ Monthly 2011] Sept
- ZOJ Monthly, August 2011 zoj 3528
- ZOJ Monthly, August 2011 zoj 3520
- ZOJ Monthly, August 2011 zoj 3523
- ZOJ 4528 ZOJ Monthly, October 2011 A
- ZOJ 4535 ZOJ Monthly, October 2011 H
- ZOJ 4536 ZOJ Monthly, October 2011 I
- ZOJ Monthly, May 2011 - B Roman Order
- ZOJ Monthly, July 2011 【B 】Cake Robbery
- ZOJ Monthly, July 2011【D】找规律
- hadoop streaming 编程
- DBUtils
- fileupload验证文件
- 大牛们的blog (人工智能与机器学习)
- SQLServer 通过DMV实现低影响的自动监控和历史场景追溯
- 求解释!!!zoj3532 ZOJ Monthly, September 2011
- 2011.09.20-UNL(2)及rup的相关知识
- Android Buildcook 编译之Android.mk文件的编写
- java中多个线程访问共享数据的方式有哪些
- 9.20随笔 UML
- 用eclipse生成javadoc的时候发生“编码 GBK 的不可映射字符
- XML
- UML之二
- Telerik ajax控件的使用