PersonalCorpus 版 (精华区)

//1Y 
//3200 2003/09/01 08:41:28.872 Accepted 0:00.002 64 C++ 2730 - Toll 

#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#include "ctype.h"
#include "string.h"
#include "memory.h"

void main()
{

#ifndef ONLINE_JUDGE
    freopen ("i","r",stdin);freopen ("o","w",stdout);
#endif

    int i,j,k,a,b,x,n,tot=0,best[52];
    char s[400], dl[52][52], p[60000];

    while (1) {
        gets(s); sscanf(s,"%d",&n);
        if (n==-1) break;
        memset(dl,0,sizeof(dl));
        while (n--) {
            gets(s);
            for (i=0;s[i]==' ';i++);
            if (s[i]>='a') a=s[i]-'a'+26; else a=s[i]-'A';
            for (++i;s[i]==' ';i++);
            if (s[i]>='a') b=s[i]-'a'+26; else b=s[i]-'A';
            dl[a][b]=dl[b][a]=1;
        }
        gets(s);
        sscanf(s,"%d",&n);
        for (i=0;s[i]!=' ';i++);
        for (++i;s[i]==' ';i++);
        if (s[i]>='a') a=s[i]-'a'+26; else a=s[i]-'A';
        for (++i;s[i]==' ';i++);
        if (s[i]>='a') b=s[i]-'a'+26; else b=s[i]-'A';

        for (i=0;i<52;i++) best[i]=20000000;
        p[0]=b; best[b]=n;
        i=0;j=1;
        while (i<j) {
            for (k=0;k<52;k++) if (dl[k][p[i]]) {
                if (p[i]<26) x=(best[p[i]]*20+18)/19; else x=best[p[i]]+1;
                if (x<best[k]) {
                    best[k]=x;
                    p[j++]=k;
                }
            }
            ++i;
        }
        printf("Case %d: %d\n",++tot,best[a]);
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:5.789毫秒