Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

郁闷中,自己测了n多数据了...........

Posted by Gary0_0 at 2005-08-20 10:33:11 on Problem 2580
#include <stdio.h>

#include <string.h>

int dor[100][2],dn;          //每扇门所连的房间,门的数量

int key[100][26],kn[100];       //开每扇门所需的钥匙和钥匙数

bool rom[20],d[100],rk[27];     //已开的房间和已开的门,已获得的钥匙 

int n,t;                       //房间数,起始房间 

int kir[20][26],km[20];           //每个房间内的钥匙和钥匙数 

char a[11];                 //临时字符串 

void iit()
{
    dn=-1;
    memset(kn,0,sizeof(kn));
    memset(rom,0,sizeof(rom));
    memset(d,0,sizeof(d));
    memset(rk,0,sizeof(rk));
    memset(km,0,sizeof(km));
}

void rdd()
{
    scanf("%d%d",&t,&n);//getchar();
    char cc='a';
    while(cc!='\n') scanf("%c",&cc);
    rom[t]=true;
    for(int i=0;i<n;i++)
    {
        char k;
        int j=0;
        bool tag=false;    //表示是否在数字串内
        while(true)
        {
            scanf("%c",&k);
            if(k>='0'&&k<='9')
            {
                if(!tag) {j=k-'0';dn++;}
                else j=j*10+(k-'0');
                tag=true;
            }
            else
            {
                if(k>='A'&&k<='Z'||tag)
                {
                    dor[dn][0]=i;
                    dor[dn][1]=j;
                    if(k>='A'&&k<='Z')
                    {
                        k-='A';
                        key[dn][kn[dn]++]=k;
                    }
                    else key[dn][kn[dn]++]=26;
                }
                tag=false;
                if(k=='\n') break;
            }
        }
    }
    dn++;
    for(int i=0;i<n;i++)
        while(true)
        {
            char c;
            scanf("%c",&c);
            if(c=='\n') break;
            else if(c>='A'&&c<='Z') kir[i][km[i]++]=c-'A';
        }
    for(int j=0;j<km[t];j++) rk[kir[t][j]]=true;
    rk[26]=true;
}    

void sol()
{
    if(t==0) {printf("YES\n");return;}
    int i,j,k,tt;
    for(i=0;i<dn;i++) if(!d[i])
    {
        int u=dor[i][0],v=dor[i][1];
        if(rom[u]&&!rom[v]||!rom[u]&&rom[v])
        {
            for(j=0;j<kn[i]&&rk[key[i][j]];j++);
            if(j==kn[i])
            {
                tt=rom[u]?v:u;
                if(tt==0) {printf("YES\n");return;}
                d[i]=true;
                rom[tt]=true;
                for(k=0;k<km[tt];k++) rk[kir[tt][k]]=true;
                i=-1;
            }
        }
    }
    printf("NO\n");
}            

int main()
{
    while(true)
    {
        scanf("%s",a);
        if(strlen(a)==10) break;
        iit();
        rdd();
        sol();
        scanf("%s",a);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator