博客
关于我
P3879 [TJOI2010]阅读理解
阅读量:337 次
发布时间:2019-03-04

本文共 801 字,大约阅读时间需要 2 分钟。

题目

制作一个数据结构,支持静态询问字符串x出现在哪些短文中并去重。

思路

首先,我们需要一个高效的数据结构来存储字符串x及其出现的位置。为了实现查找功能,我们可以使用std::map来存储键为字符串x,值为一个std::set

的映射。std::set不仅可以自动去重,还能快速查找元素是否存在,这样我们就能快速判断x是否出现在文本中。通过这种方式,我们可以在O(log n)的时间复杂度内完成查找和插入操作。

#include 
#include
#include
#include
#include
#include
using namespace std;map
> a;int n, m;string x;int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> m; for (int j = 0; j < m; ++j) { cin >> x; a[x].insert(i + 1); } } cin >> n; for (int i = 0; i < n; ++i) { cin >> x; if (a.find(x) != a.end()) { for (set
::iterator it = a[x].begin(); it != a[x].end(); ++it) { cout << *it << ' '; } } } return 0;}

转载地址:http://vfye.baihongyu.com/

你可能感兴趣的文章
Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
查看>>
Network Sniffer and Connection Analyzer
查看>>
Network 灰鸽宝典【目录】
查看>>
NetworkX系列教程(11)-graph和其他数据格式转换
查看>>
Networkx读取军械调查-ITN综合传输网络?/读取GML文件
查看>>
network小学习
查看>>
Netwox网络工具使用详解
查看>>
Net与Flex入门
查看>>
net包之IPConn
查看>>
Net操作配置文件(Web.config|App.config)通用类
查看>>
Neutron系列 : Neutron OVS OpenFlow 流表 和 L2 Population(7)
查看>>
New Relic——手机应用app开发达人的福利立即就到啦!
查看>>
NFinal学习笔记 02—NFinalBuild
查看>>
NFS
查看>>
NFS Server及Client配置与挂载详解
查看>>
NFS共享文件系统搭建
查看>>
nfs复习
查看>>
NFS安装配置
查看>>
NFS的安装以及windows/linux挂载linux网络文件系统NFS
查看>>
NFS的常用挂载参数
查看>>