【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). ...
随机推荐
- 资料收集:学习 Linux/*BSD/Unix 的 30 个最佳在线文档
文章转自:https://linux.cn/article-10311-1.html 手册页(man)是由系统管理员和 IT 技术开发人员写的,更多的是为了作为参考而不是教你如何使用.手册页对于已经熟 ...
- 白话SpringCloud | 第七章:分布式配置中心的使用
前言 介绍完服务的容错保护处理,接下来我们来了解下关于分布式配置中心的相关知识和使用.众所周知,随着项目的越来越多,日益庞大,每个子项目都会伴随着不同的配置项,于此也就多了很多的配置文件.倘若某些配置 ...
- 关于FileFOutputStream应用中的FileNotFoundException问题
在使用fileoutputstream时经常出现FileNotFoundException问题,即便是同一个程序(可行)改了一下包名再重新编译,就会无缘无故的抛出FileNotFoundExcepti ...
- webpack管理资源
加载Css webpack并不能处理js以外的静态资源,通过loader来支持他们 npm install --save-dev style-loader css-loader const path ...
- sort属性
学习文章---链接 总结笔记 ①sort是Array.prototype的属性, ②如果不写入参数,则按照转换为的字符串的每个字符的unicode位点进行排序, ③如果传入一个比较函数sort(fun ...
- Gson 转换hibernate级联对象出现StackOverFlow(堆栈溢出)问题
< many-to-one>和< one-to-many>属性的对象级联关系在转换时会造成死循环,报stackOverFlowException. 比如下面这段: @OneTo ...
- ORACLE中一个字符占多少字节?
问题描述 或许你会说一个中文字符占2个字节,这是一定的?如何计算一个字符串的字节数? 解决方案 在oracle中一个字符特别是中文占几个字节是不同的. 比如我创立一个表create table tes ...
- winform中 让 程序 自己重启
private void button1_Click(object sender, EventArgs e) { Application.ExitThread(); ...
- sqlserver 带输出参数的存储过程
--创建存储过程create procedure proc_stu@sname varchar(20),@pwd varchar(50),@flag bit outputasif exists(sel ...
- html-表单的设计
一.表单的设计 1.注册表单页面 <html> <head> <title>表单的练习</title> <script> function ...