zoukankan      html  css  js  c++  java
  • 【luogu P2580 于是他错误的点名开始了】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2580

    我真的永远都爱stl

    #include <map>
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int maxn = 100001;
    map<string,int> a;
    int n, m, num[maxn];
    string s;
    int main()
    {
    	memset(num,-1,sizeof(num));
    	scanf("%d",&n);
    	for(int i = 1; i <= n; i++)
    	{
    		cin>>s;
    		a[s] = i;
    		num[a[s]]++;
    	}
    	scanf("%d",&m);
    	for(int i = 1; i <= m; i++)
    	{
    		cin>>s;
    		if(num[a[s]] ==-1)
    		{
    			printf("WRONG
    ");
    			continue;//记得continue一下,要不然重复点错名的话会出错
    		}
    		num[a[s]]++;
    		if(num[a[s]] == 1)
    		{
    			printf("OK
    ");
    		}
    		if(num[a[s]] > 1)
    		{
    			printf("REPEAT
    ");
    		}
    	}
    	return 0;
    }
    

    后来我发现,trie也很棒棒哦qaq

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    const int maxn = 500001;
    char s[50];
    int n, m, v[maxn], trie[maxn][26], opt, tot; 
    void insert()
    {
    	int len = strlen(s);
    	int root = 0;
    	for(int i = 0; i < len; i++)
    	{
    		int id = s[i] - 'a';
    		if(!trie[root][id])
    			trie[root][id]=++tot;
    		root = trie[root][id];	
    	}
    	v[root] = 1;
    }
    int find()
    {
    	int len = strlen(s);
    	int root = 0;
    	for(int i = 0; s[i]; i++)
    	{
    		int now = s[i] - 'a';
    		if(trie[root][now] == 0) return false;
    		root = trie[root][now];
    	}
    	if(v[root] == 1)
    	{
    		v[root] = 2;
    		return 1;
    	}
    	else
    	return 2;
    }
    int main()
    {
    	std::ios::sync_with_stdio(false);
    	cin>>n;
    	for(int i = 1; i <= n; i++)
    	{
    		cin>>s;
    		insert();
    	}
    	cin>>m;
    	for(int i = 1; i <= m; i++)
    	{
    		cin>>s;
    		opt = find();
    		if(opt == 0) printf("WRONG
    ");
    		if(opt == 1) printf("OK
    ");
    		if(opt == 2) printf("REPEAT
    ");
    	}
    }
    

    隐约雷鸣,阴霾天空,但盼风雨来,能留你在此。

    隐约雷鸣,阴霾天空,即使天无雨,我亦留此地。

  • 相关阅读:
    《简养脑》读书笔记
    如何用86天考上研究生
    Improving your submission -- Kaggle Competitions
    Getting started with Kaggle -- Kaggle Competitions
    入门机器学习
    《世界因你不同》读书笔记
    [转载]Python 包构建教程
    [转载] Pytorch拓展进阶(二):Pytorch结合C++以及Cuda拓展
    集合不能存放重复元素
    在jupyter notebook中绘制KITTI三维散点图
  • 原文地址:https://www.cnblogs.com/MisakaAzusa/p/9216212.html
Copyright © 2011-2022 走看看