题目链接: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\n");
continue;//记得continue一下,要不然重复点错名的话会出错
}
num[a[s]]++;
if(num[a[s]] == 1)
{
printf("OK\n");
}
if(num[a[s]] > 1)
{
printf("REPEAT\n");
}
}
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\n");
if(opt == 1) printf("OK\n");
if(opt == 2) printf("REPEAT\n");
}
}

【luogu P2580 于是他错误的点名开始了】 题解的更多相关文章

  1. luogu P2580 于是他错误的点名开始了

    luogu  P2580 于是他错误的点名开始了 https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边 ...

  2. Luogu P2580 于是他错误的点名开始了 Trie树 字典树

    字典树裸题.每次插入询问串,查询的时候拿出来直接查,信息保留在节点上. #include <bits/stdc++.h> using namespace std; char s[51]; ...

  3. LUOGU P2580 于是他错误的点名开始了(trie树)

    传送门 解题思路 trie树模板

  4. 洛谷P2580 于是他错误的点名开始了 题解

    qwq!为什么!木有非结构体非指针的题解怎么阔以!所以, 我来辽~咻咻咻~ 题面 来分析, 我们可以先建一棵树,来存储整个名单, 然后再判断 ; i <= n; i++) { root = ; ...

  5. 洛谷 P2580 于是他错误的点名开始了 题解

    每日一题 day10 打卡 Analysis trie树模板题,只需用到简单的插入和查询就好了 如果想要学trie树,见信息学奥赛一本通·提高篇P82 #include<iostream> ...

  6. [Luogu 2580] 于是他错误的点名开始了

    [Luogu 2580] 于是他错误的点名开始了 不用好奇我为什么突然发水题题解- 突然觉得自己当年的幼儿园码风太幼稚,就试图把数据结构什么的用指针重写一遍- 想当年因为空间开太大而全 RE,调了一下 ...

  7. P2580 于是他错误的点名开始了(trie)

    P2580 于是他错误的点名开始了 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉 ...

  8. 洛谷—— P2580 于是他错误的点名开始了

    https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次 ...

  9. P2580 于是他错误的点名开始了

    题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...

随机推荐

  1. 使用params

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. Django自定义登陆验证后台

    支持邮箱/手机号/昵称登录,在django1.6.2测试成功.1.models # -*- encoding: utf-8 -*- from django.db import models from ...

  3. centOS使用.htaccess

    首先,你要保证你的Aapche已经开启了.htaccess 可以参考:http://www.veryhuo.com/a/view/21259.html 以下是.htaccess文件中的内容: Rewr ...

  4. Coursera 机器学习 第8章(下) Dimensionality Reduction 学习笔记

    8 Dimensionality Reduction8.3 Motivation8.3.1 Motivation I: Data Compression第二种无监督问题:维数约简(Dimensiona ...

  5. java I/O流 温习随笔

    java I/O流的熟练掌握是十分重要的. 在我的理解中,I/O流可以分为两种:字符流.字节流.字符流就是可以用来传输字符的流,比如传输txt文本,简单的说,只有能被电脑中的记事本直接打开并且你能看懂 ...

  6. win10的xbox下载应用或者游戏时,出现0x80070422和0x80073D0A的解决办法

    这个错误:0x80070422是因为关闭了windows update这个服务导致的 这个错误:0x80073D0A是因为关闭了windows firewall这个服务导致的 具体操作: cmd下se ...

  7. 破解jar包5步搞定,jira7.9.2操作成功,附github代码库

    1,从要破解的程序中拷贝.jar包文件,运行1_jar.sh将其解压.以jira7.9.2为例: $install_dir\JIRA\atlassian-jira\WEB-INF\lib\atlass ...

  8. 编写可维护的 Gruntfile.js

    load-grunt-tasks 插件 首先介绍下 load-grunt-tasks 这个插件. 我们一般都会把所有用到的插件以及插件的配置写到 Gruntfile.js 里面,对于小项目来说这个文件 ...

  9. GUID 格式化

    1.Guid.NewGuid().ToString("N") 结果为: 38bddf48f43c48588e0d78761eaa1ce6 2.Guid.NewGuid().ToSt ...

  10. 检查你要加入到gradle的第三方library是否是最新版本

    开发者从博客.github readme  或者 官方文档中找到如何在gradle 文件中加入dependency  的时候,往往版本已经比较老旧了,想要找到最新版,介绍一个利器 http://gra ...