zoukankan      html  css  js  c++  java
  • Luogu2580 于是他错误的点名开始了 (Trie树)

    复习(Trie),忘了用(val[])表示每个节点权值,用(vis[])水过了

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
    #define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
    #define Max(a,b) ((a) > (b) ? (a) : (b))
    #define Min(a,b) ((a) < (b) ? (a) : (b))
    #define Fill(a,b) memset(a, b, sizeof(a))
    #define Abs(a) ((a) < 0 ? -(a) : (a))
    #define Swap(a,b) a^=b^=a^=b
    #define ll long long
    
    #define ON_DEBUG
    
    #ifdef ON_DEBUG
    
    #define D_e_Line printf("
    
    ----------
    
    ")
    #define D_e(x)  cout << #x << " = " << x << endl
    #define Pause() system("pause")
    #define FileOpen() freopen("in.txt","r",stdin);
    
    #else
    
    #define D_e_Line ;
    #define D_e(x)  ;
    #define Pause() ;
    #define FileOpen() ;
    
    #endif
    
    struct ios{
        template<typename ATP>ios& operator >> (ATP &x){
            x = 0; int f = 1; char c;
            for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
            while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
            x*= f;
            return *this;
        }
    }io;
    using namespace std;
    #include <bitset>
    
    int n;
    
    char s[1007];
    bitset<1007> vis[500007];
    int trie[500007][26], trieIndex;
    inline void Insert(char *str){
    	int rt = 0;
    	for(register int i = 0; str[i] != ''; ++i){
    		int v = str[i] - 'a';
    		if(!trie[rt][v]){
    			trie[rt][v] = ++trieIndex;
    		}
    		rt = trie[rt][v];
    	}
    }
    inline int Query(char *str){
    	int rt = 0, tot = 0;
    	for(register int i = 0; str[i] != ''; ++i){
    		int v = str[i] - 'a';
    		if(!trie[rt][v]){
    			return 0;
    		}
    		rt = trie[rt][v];
    		++tot;
    	}
    	if(vis[rt][tot]) return 2;
    	vis[rt][tot] = 1;
    	return 1;
    }
    
    int main(){
        io>>n;
        R(i,1,n){
        	scanf("%s", s);
        	Insert(s);
        }
        
        int Ques;
        io >> Ques;
        while(Ques--){
        	scanf("%s", s);
        	int ans = Query(s);
        	switch(ans){
        		case 0 :{
        			printf("WRONG
    ");
        			break;
        		}
        		case 1 :{
        			printf("OK
    ");
        			break;
        		}
        		case 2 :{
        			printf("REPEAT
    ");
        			break;
        		}
        	}
        }
        
        return 0;
    }
    

  • 相关阅读:
    springboot的@EnableAutoConfiguration起作用的原理
    springboot加载bean过程探索
    dubbo源码阅读笔记-如何引用远程服务,变成invoker
    HashMap如何实现序列化
    如果处理缓存失效从数据库加载数据
    redis设计原则
    redis相关运维命令
    spring的compentScan注解扫描类机制
    全文检索技术
    前端设计网站
  • 原文地址:https://www.cnblogs.com/bingoyes/p/11237360.html
Copyright © 2011-2022 走看看