| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 604 人关注过本帖
标题:哪位好心人教下我这道题Time Limit Exceed怎么改进TAT
只看楼主 加入收藏
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
结帖率:77.78%
收藏
已结贴  问题点数:20 回复次数:5 
哪位好心人教下我这道题Time Limit Exceed怎么改进TAT
2437: English word
Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 2362  Solved: 1137

Description
You still are worried about reading acm English problem, let me tell you a kind of very good method of Memorising Words, the root memory method,.the most interesting of the method is the prefix root. Now there are some English words to remembeand he knows some prefix root;He want to know how many words that can be remembered using each the prefix .in other words,how many words that contain the prefix ,Now to acmer you for help, can you help him?


Input
The input consists of T test cases. The number of them (T) is given on the first line of the input file. Each test case begins with a line containing a single integer number N that indicates the number of words (1 <= N <= 10000). Then exactly N lines follow, each containing a single word. Each word contains at least two and at most 10 lowercase characters, that means only letters 'a' through 'z' will appear in the word. The same word may appear several times in the list. Then follow a line containing a single integer number M that indicates the number of Words prefix question (0 <= M<= 10000). Then exactly M lines follow, each containing a single Words prefix.
Output
For the given input data, output exact M line, each line contain a ingle integer indicates the answer of each query.
Sample Input
1
4
preview
predict
premier
press
3
pre
press
pree

Sample Output
4
1
0

我的代码:
#include<stdio.h>
#include<string.h>
int main()
{
    int T,N,M,i,j,k,count,flag,e;
   char a[10000][10],b[10000][10];
    int c[10000];
    scanf("%d",&T);
    getchar();
    scanf("%d",&N);
    getchar();
    for(e=1;e<=T;e++)
    {
    for(i=0;i<=N-1;i++)
    {
        gets(a[i]);
    }
    scanf("%d",&M);
    getchar();
    for(i=0;i<=M-1;i++)
    {
        gets(b[i]);
        c[i]=strlen(b[i]);
    }
     for(i=0;i<=M-1;i++)//na b[1],b[2]...
     {
         count=0;
         for(k=0;k<=N-1;k++)
         {
          for(j=0;j<=c[i]-1;j++)
          {
              flag=0;
            if(b[i][j]!=a[k][j])
            {flag=1;break;}
           }
           if(flag==0)
           {count++;}
          }
       printf("%d\n",count);   
      }
  }
      return 0;
  }
   
跪谢啦~~
搜索更多相关主题的帖子: English reading contain problem memory 
2013-11-27 14:48
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
运行结果是对的。。。
2013-11-27 14:49
pink_duo
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
帖 子:209
专家分:1054
注 册:2013-11-5
收藏
得分:0 
楼主,你有好好读题目要求么

埋头做牛,抬头做人,低头做狗
2013-11-27 14:53
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
回复 3楼 pink_duo
。。。是什么要求漏掉了??
2013-11-27 15:17
czz5242199
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:660
专家分:2400
注 册:2011-10-26
收藏
得分:20 
程序代码:
#include <stdio.h>
#include <stdlib.h>

struct node
{
    int flag;
    struct node* p[26];
}*head;

void find(char *s,struct node* head)
{
    int i,temp;
    (head->flag)++;

    if (s[0]==0) return;
    temp=s[0]-'a';
    if (head->p[temp]==NULL)
    {
        head->p[temp]=malloc(sizeof(struct node));
        head->p[temp]->flag=0;
        for (i=0; i<26; i++)
            head->p[temp]->p[i]=NULL;
    }
    find(s+1,head->p[temp]);
}

void output(char *s,struct node *head)
{
    while (head!=NULL && s[0]!=0) 
    {
        head=head->p[s[0]-'a'];
        s++;
    }
    if (head==NULL) printf("0\n"); 
        else printf("%d\n",head->flag);
}

int main()
{
    int T,N,M,i;
    char s[15];
    scanf("%d",&T);
    while (T--)
    {
        head=malloc(sizeof(struct node));
        head->flag=0; 
        for (i=0; i<26; i++) head->p[i]=NULL;

        scanf("%d",&N);
        while (N--)
        {
            scanf("%s",s);
            find(s,head);
        }

        scanf("%d",&M);
        while (M--)
        {
            scanf("%s",s);
            output(s,head);
        }
    }
}
        
收到的鲜花
  • LeslieCh2013-11-28 20:14 送鲜花  3朵   附言:好文章
2013-11-27 16:24
LeslieCh
Rank: 1
等 级:新手上路
帖 子:33
专家分:0
注 册:2013-11-27
收藏
得分:0 
回复 5楼 czz5242199
谢谢你啊~成功AC了!
2013-11-28 20:14
快速回复:哪位好心人教下我这道题Time Limit Exceed怎么改进TAT
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023410 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved