博客
关于我
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/

你可能感兴趣的文章
Node.js 8 中的 util.promisify的详解
查看>>
node.js debug在webstrom工具
查看>>
Node.js RESTful API如何使用?
查看>>
node.js url模块
查看>>
Node.js Web 模块的各种用法和常见场景
查看>>
Node.js 之 log4js 完全讲解
查看>>
Node.js 函数是什么样的?
查看>>
Node.js 函数计算如何突破启动瓶颈,优化启动速度
查看>>
Node.js 切近实战(七) 之Excel在线(文件&文件组)
查看>>
node.js 初体验
查看>>
Node.js 历史
查看>>
Node.js 在个推的微服务实践:基于容器的一站式命令行工具链
查看>>
Node.js 实现类似于.php,.jsp的服务器页面技术,自动路由
查看>>
Node.js 异步模式浅析
查看>>
node.js 怎么新建一个站点端口
查看>>
Node.js 文件系统的各种用法和常见场景
查看>>
Node.js 模块系统的原理、使用方式和一些常见的应用场景
查看>>
Node.js 的事件循环(Event Loop)详解
查看>>
node.js 简易聊天室
查看>>
Node.js 线程你理解的可能是错的
查看>>