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

你可能感兴趣的文章
nginx + etcd 动态负载均衡实践(二)—— 组件安装
查看>>
nginx + etcd 动态负载均衡实践(四)—— 基于confd实现
查看>>
Nginx + Spring Boot 实现负载均衡
查看>>
Nginx + uWSGI + Flask + Vhost
查看>>
Nginx - Header详解
查看>>
Nginx Location配置总结
查看>>
Nginx Lua install
查看>>
Nginx upstream性能优化
查看>>
Nginx 中解决跨域问题
查看>>
Nginx 动静分离与负载均衡的实现
查看>>
Nginx 反向代理 MinIO 及 ruoyi-vue-pro 配置 MinIO 详解
查看>>
nginx 反向代理 转发请求时,有时好有时没反应,产生原因及解决
查看>>
Nginx 反向代理解决跨域问题
查看>>
Nginx 反向代理配置去除前缀
查看>>
nginx 后端获取真实ip
查看>>
Nginx 学习总结(16)—— 动静分离、压缩、缓存、黑白名单、性能等内容温习
查看>>
Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置
查看>>
Nginx 常用配置清单
查看>>
nginx 常用配置记录
查看>>
Nginx 我们必须知道的那些事
查看>>