MPI Maelstrom poj 1502
来源:互联网 发布:windows不是正版7601 编辑:程序博客网 时间:2024/04/29 22:39
这道题算是过得顺利的,一次ac,水。
主要是处理字符串和数字的转换~
acsii码就是(字符-48)即为数字。
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int inf = 0x3f3f3f3f;int edge[105][105],n,dict[105];bool vis[105];int maxx(int x,int y) { if(x > y) return x; else return y;}void dijkstra() { int min,k,now = 1; for(int t = 1;t <= n;t++) { min = inf; for(int i = 2;i <= n;i++) { if(!vis[i]) { if(edge[now][i] != inf && dict[i] > dict[now] + edge[now][i]) dict[i] = dict[now] + edge[now][i]; if(min > dict[i]) min = dict[k = i]; } } vis[k] = true; now = k; }}int main() { while(scanf("%d",&n) != EOF) { char chao[20];int num; memset(vis,false,sizeof(vis)); memset(dict,inf,sizeof(dict)); dict[1] = 0;vis[1] = true; for(int i = 2;i <= n;i++) { for(int j = 1;j <= i-1;j++) {//输入字符串并且转换为数字 cin>>chao; if(chao[0] == 'x') num = inf; else { num = 0; int len = strlen(chao); int cnt = 0,tt,nn; while(chao[cnt] != '\0') { nn = len-1,tt = 1; while(nn--) tt *= 10; num += (chao[cnt]-48)*tt; len--;cnt++; } } edge[i][j] = edge[j][i] = num; } } for(int i = 1;i <= n;i++) edge[i][i] = 0; dijkstra(); int ans = 0; for(int i = 1;i <= n;i++) ans = maxx(ans,dict[i]); printf("%d\n",ans); }}
0 0
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ-1502-MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj 1502:MPI Maelstrom
- poj 1502: MPI Maelstrom
- POJ 1502 MPI Maelstrom
- poj-1502 MPI Maelstrom
- 使用onfocus实现输入框的placeholder
- jvm优雅关闭:
- 思讯823错误
- 人工智能常用 API
- Activity四种启动模式
- MPI Maelstrom poj 1502
- 事件绑定addEventListener
- 使用ThinkPHP框架开发中怎么有效保证多文件上传不重复呢
- logback.xml
- 事件的捕获
- win10备份
- C/C++语言参数传递----值传递、引用传递、指针传递、指针引用传递
- 【COCI2008】猴子摘桃
- Java下利用Jackson进行JSON解析和序列化