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

求助哇......哪位牛人指点一下,我这个搜索部分怎么老是超时呢?....

Posted by mythology at 2007-08-05 10:57:37 on Problem 2491
#include <stdio.h>
#include <string.h>

struct tt
{
    char  s1[100],s2[100];
}z[334];


int  main ()
{
    int  n,i,m,j;
    scanf("%d",&n);

    for(i=1;i<=n;i++)
    {
        int  k,p,s3[350]={0};
        scanf("%d",&m);
 
        m-=1;
        for(j=0;j<m;j++)
          scanf("%s%s",z[j].s1,z[j].s2);
        
        k=m-1;
        for(j=m-1;j>=0;j--)                                  /*找出开始的那个字符串*/
        {
            for(p=j-1;p>=0;p--)
            {
               if(!strcmp(z[j].s1,z[p].s2))
               {
                     k=p;
                     break;
               }
            }
            if(p>=0)
                break;
        }                                                    /*找出开始的那个字符串*/

        printf("Scenario #%d:\n",i);

        printf("%s\n",z[k].s1);                              /*打出开始的那个字符串*/

        s3[k]=1;

        p=1; 
        
        /*我觉得错误就出现在 这个部分...可就是检查不出来......循环没跳出来,还请各位大牛指点一下小弟啊.....小弟感激不尽呐....*/
        for(j=0;j<m;j++)                                       /*依次搜索下一个字符串*/
        {
           if(!strcmp(z[k].s2,z[j].s1) && s3[j]==0)
            {
                printf("%s\n",z[j].s1);
                k=j;
                p++;
                s3[j]=1;
            }
            if(p>=m-1)
                break;

            if(j==m-1)
                j=-1;
        }                                                      /*依次搜索下一个字符串*/
        printf("%s\n\n",z[k].s2);                              /*打出最后一个没有在上面循环被打出的最后一个字符串*/
    }
}




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