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

Re:1002,超时了,求大牛们解释下哪里弄复杂了。。。

Posted by ixor at 2011-03-04 17:14:38 on Problem 1002
In Reply To:1002,超时了,求大牛们解释下哪里弄复杂了。。。 Posted by:hl520 at 2011-02-19 23:23:29
while(n--)
    {
        gets(s);p=s;fun(p);
        for(i=0;i<flag;i++)
        {
            if(strcmp(p,x[i].a)==0)
            {
              (x[i].m)++;break;
            }
        }
        if(i==flag) {x[flag].m=1;memcpy(x[flag].a,p,sizeof(x[flag].a));flag++;}
    }
别的不说,这段足够让代码超时好几次了,处理字符数据的时候尽量不要硬着来(稍微变通一些),不要在循环里动辄调用函数,写算法题可以稍微忽略一点代码结构。另外,你的switch case也有些慢。最后,说一句,简单的数据表示往往能带来简洁的算法,所以是否使用结构体,请慎重。

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