2 条题解

  • 0
    @ 2026-4-26 11:14:39
    #include<bits/stdc++.h>
    using namespace std;
    const int N=1e6+10;
    char s[70];int id,ch[N][26];
    int main()
    {
    	while(scanf("%s",s)!=EOF)
    	{
    		for(int i=0,p=0;s[i];i++)
    		{
    			int &_=ch[p][s[i]-'A'];
    			if(!_)_=++id;p=_;
    		}
    	}
    	printf("%d\n",id+1);
    	return 0;
    }
    
    • 0
      @ 2025-10-8 16:59:48

      F06 字典树(Trie)

      #include <bits/stdc++.h>
      using namespace std;
      const int N=1<<16;
      char str[110];
      int id,ch[N][26];
      void ins(char *s)
      {
          int p=0;
          for(int i=0;s[i];i++)
          {
              int j=s[i]-'A';
              if(ch[p][j]==0)ch[p][j]=++id;
              p=ch[p][j];
          }
      }
      
      int main()
      {
          id=0;memset(ch,0,sizeof(ch));
          while(scanf("%s",str)!=EOF)ins(str);
          printf("%d\n",id+1);
          return 0;
      }
      
      • 1

      F06*【字典树】[NOI2000] 单词查找树

      信息

      ID
      2032
      时间
      1000ms
      内存
      128MiB
      难度
      6
      标签
      递交数
      137
      已通过
      44
      上传者