| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
菜鸟搜索 没想到能过 高兴 嘿嘿嘿#include <stdio.h>
#include <string.h>
int n, f, max, k;
int map[201][201], mark[201][201];
char city[201][31], c[31];
int num() //把城市编成号码
{
int num, i = 0;
if(k > 0)
for (i=1; i<=k; i++)
if (strcmp(city[i], c) == 0)
{
num = i;
break;
}
if (i > k || k == 0){
strcpy(city[++k], c);
num = k;
}
return num;
}
void search(int i, int dj) //dj代表权值
{
if (max >= dj) return; //剪枝
if (i == f)
{
max = dj;
return;
}
for (int j=1; j<=n; j++)
{
if (mark[i][j]) //剪枝 已搜索
return;
if (map[i][j])
{
mark[i][j] = 1;
if (dj <= map[i][j])
search(j, dj);
else search(j, map[i][j]);
}
}
return;
}
int main()
{
int r, a, b, w, count = 1;
while (scanf("%d%d", &n, &r), n, r)
{
memset(map, 0, sizeof (map));
memset(mark, 0, sizeof (mark));
k = 0;
while (r--)
{
scanf("%s", c);
a = num();
scanf("%s", c);
b = num();
scanf("%d", &w);
map[a][b] = map[b][a] = w;
}
scanf("%s", c);
a = num();
scanf("%s", c);
f = num();
max = 0;
search(a, 10001);//从起始城市搜索 把权值赋为最大
printf("Scenario #%d\n%d tons\n\n", count++, max);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator