PersonalCorpus 版 (精华区)

904205 2002/06/15 08:22:18.981
Big Guava ... 459 C++ Accepted 0:00.010 64

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>

void main()
{
#ifndef ONLINE_JUDGE
    freopen("c:\\uva\\input459.txt","r",stdin);
    freopen("c:\\uva\\output459.txt","w",stdout);
#endif

    int n,i,j,k,tot;
    char s[100],max;
    char dl[91][91];
    char path[30];
    char used[91];

    scanf("%d\n",&n);
    while (n>0) {
        n--;
        gets(s);
        max=s[0];
        memset(dl,0,sizeof(dl));
        memset(used,0,sizeof(used));
        while (1) {
            if (gets(s)==NULL) break;
            if (s[0]==0) break;
            dl[s[0]][s[1]]=1;
            dl[s[1]][s[0]]=1;
        }
        tot=0;
        do {
            for (i='A';i<=max;i++) if (used[i]==0) break;
            if (i>max) break;
            path[0]=i;
            i=0;j=1;
            while (i<j) {
                for (k='A';k<=max;k++) if 
((used[k]==0)&&(dl[path[i]][k]==1)) {
                    path[j]=k;
                    j++;
                    dl[path[i]][k]=0;
                    dl[k][path[i]]=0;
                }
                i++;
            }
            tot++;
            for (i=0;i<j;i++) used[path[i]]=1;
        } while (1);
        printf("%d\n",tot); if (n>0) printf("\n");
    }
}
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.318毫秒