【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\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 于是他错误的点名开始了】 题解的更多相关文章
- luogu P2580 于是他错误的点名开始了
luogu P2580 于是他错误的点名开始了 https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边 ...
- Luogu P2580 于是他错误的点名开始了 Trie树 字典树
字典树裸题.每次插入询问串,查询的时候拿出来直接查,信息保留在节点上. #include <bits/stdc++.h> using namespace std; char s[51]; ...
- LUOGU P2580 于是他错误的点名开始了(trie树)
传送门 解题思路 trie树模板
- 洛谷P2580 于是他错误的点名开始了 题解
qwq!为什么!木有非结构体非指针的题解怎么阔以!所以, 我来辽~咻咻咻~ 题面 来分析, 我们可以先建一棵树,来存储整个名单, 然后再判断 ; i <= n; i++) { root = ; ...
- 洛谷 P2580 于是他错误的点名开始了 题解
每日一题 day10 打卡 Analysis trie树模板题,只需用到简单的插入和查询就好了 如果想要学trie树,见信息学奥赛一本通·提高篇P82 #include<iostream> ...
- [Luogu 2580] 于是他错误的点名开始了
[Luogu 2580] 于是他错误的点名开始了 不用好奇我为什么突然发水题题解- 突然觉得自己当年的幼儿园码风太幼稚,就试图把数据结构什么的用指针重写一遍- 想当年因为空间开太大而全 RE,调了一下 ...
- P2580 于是他错误的点名开始了(trie)
P2580 于是他错误的点名开始了 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉 ...
- 洛谷—— P2580 于是他错误的点名开始了
https://www.luogu.org/problem/show?pid=2580 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次 ...
- P2580 于是他错误的点名开始了
题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛CON900). ...
随机推荐
- unity的assetbundle的自动命名,以我的命名lua为例
static string testDir = "Assets/LuaScripts/"; [MenuItem("测试/lua命名")] public stat ...
- Nginx使用的php-fpm的两种进程管理方式及优化
PS:前段时间配置php-fpm的时候,无意中发现原来它还有两种进程管理方式.与Apache类似,它的进程数也是可以根据设置分为动态和静态的. php-fpm目前主要又两个分支,分别对应于php-5. ...
- Coursera 机器学习 第5章 Neural Networks: Learning 学习笔记
5.1节 Cost Function神经网络的代价函数. 上图回顾神经网络中的一些概念: L 神经网络的总层数. sl 第l层的单元数量(不包括偏差单元). 2类分类问题:二元分类和多元分类. 上 ...
- Jersey统一异常处理
众所周知,java服务提供者提供给服务请求者应该是特定格式的数据,而不能出现异常栈类似信息,那么jersey中,如何添加统一的异常处理呢? 针对jersey启动如果是实现了ResourceConfig ...
- 【SoapUI】http接口测试
一.接口介绍 API(Application Programming Interface,应用程序编程接口) 1.硬件接口 USB接口 硬盘接口 SD卡接口 LAN口和WAN口 CONSOLE口 .. ...
- MAC 下安装RabbitMQ
1.使用brew来安装 RabbitMQ(地址:http://www.rabbitmq.com/install-standalone-mac.html ) 2.安装目录 /usr/local/Cell ...
- 使用c#正则验证关键字并找出匹配项
在.net里,使用类Regex可以正则验证一些关键字并取出匹配项. 1.使用Regex.IsMatch(string input, string pattern, RegexOptions ...
- 将金额数字转换为大写汉字的js函数
//将金额数字转换为大写汉字的函数 function convertCurrency(money) { //汉字的数字 var cnNums = new Array('零', '壹', '贰', '叁 ...
- Git for Android Studio 学习笔记
http://learngitbranching.js.org/ 一个特别好的git学习教程 创建一个project,然后导入github
- OLEDB存取BLOB型数据
现代数据库系统除了支持一些标准的通用数据类型以外,大多数还支持一种称之为BLOB型的数据. BLOB全称为big large object bytes, 大二进制对象类型,这种类型的数据通常用于存储文 ...