当前位置:网站首页>[NOIP2010 提高组] 机器翻译
[NOIP2010 提高组] 机器翻译
2022-08-05 07:31:00 【Recursi】
[NOIP2010 提高组] 机器翻译
题目背景
小晨的电脑上安装了一个机器翻译软件,他经常用这个软件来翻译英语文章。
题目描述
这个翻译软件的原理很简单,它只是从头到尾,依次将每个英文单词用对应的中文含义来替换。对于每个英文单词,软件会先在内存中查找这个单词的中文含义,如果内存中有,软件就会用它进行翻译;如果内存中没有,软件就会在外存中的词典内查找,查出单词的中文含义然后翻译,并将这个单词和译义放入内存,以备后续的查找和翻译。
假设内存中有 M M M 个单元,每单元能存放一个单词和译义。每当软件将一个新单词存入内存前,如果当前内存中已存入的单词数不超过 M − 1 M-1 M−1,软件会将新单词存入一个未使用的内存单元;若内存中已存入 M M M 个单词,软件会清空最早进入内存的那个单词,腾出单元来,存放新单词。
假设一篇英语文章的长度为 N N N 个单词。给定这篇待译文章,翻译软件需要去外存查找多少次词典?假设在翻译开始前,内存中没有任何单词。
输入格式
共 2 2 2 行。每行中两个数之间用一个空格隔开。
第一行为两个正整数 M , N M,N M,N,代表内存容量和文章的长度。
第二行为 N N N 个非负整数,按照文章的顺序,每个数(大小不超过 1000 1000 1000)代表一个英文单词。文章中两个单词是同一个单词,当且仅当它们对应的非负整数相同。
输出格式
一个整数,为软件需要查词典的次数。
样例 #1
样例输入 #1
3 7
1 2 1 5 4 4 1
样例输出 #1
5
提示
样例解释
整个查字典过程如下:每行表示一个单词的翻译,冒号前为本次翻译后的内存状况:
1
:查找单词 1 并调入内存。1 2
:查找单词 2 并调入内存。1 2
:在内存中找到单词 1。1 2 5
:查找单词 5 并调入内存。2 5 4
:查找单词 4 并调入内存替代单词 1。2 5 4
:在内存中找到单词 4。5 4 1
:查找单词 1 并调入内存替代单词 2。
共计查了 5 5 5 次词典。
数据范围
- 对于 10 % 10\% 10% 的数据有 M = 1 M=1 M=1, N ≤ 5 N \leq 5 N≤5;
- 对于 100 % 100\% 100% 的数据有 1 ≤ M ≤ 100 1 \leq M \leq 100 1≤M≤100, 1 ≤ N ≤ 1000 1 \leq N \leq 1000 1≤N≤1000。
/* * @Description: To iterate is human, to recurse divine. * @Autor: Recursion * @Date: 2022-08-04 01:59:07 * @LastEditTime: 2022-08-04 02:11:37 */
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e9 + 10;
const int N = 1e6;
vector <int> v;
int n,m;
int a[N];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> m >> n;
int t;
int ans = 0;
for(int i = 1;i <= n;i ++){
cin >> t;
if (std::find(v.begin(), v.end(), t) == v.end()) {
v.push_back(t);
++ans;
}
if (v.size() > m)
v.erase(v.begin());
}
cout << ans << endl;
return 0;
}
边栏推荐
- Does Libpq support read-write separation configuration?
- 不能比较或排序 text、ntext 和 image 数据类型
- Stored procedure writing experience and optimization measures
- YOLOv3 SPP理论详解(包括CIoU及Focal loss)
- cmake 学习使用笔记(三)
- 每月稳定干2万
- Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
- 【 LeetCode 】 235. A binary search tree in recent common ancestor
- Support touch screen slider carousel plugin
- Flink学习11:flink程序并行度
猜你喜欢
随机推荐
Tencent Business Security Post IDP Talk Summary
【LeetCode】235.二叉搜索树的最近公共祖先
专用机终端安装软件后报IP冲突
学习机赛道加速:请“卷”产品,不要“卷”营销
Liunx教程超详细(完整)
小本创业者的致胜法宝!
Invalid operator for data type.The operator is add and the type is text.
[instancetype type Objective-C]
uniapp时间组件封装年-月-日-时-分-秒
SVG星球大战样式Toggle切换开关按钮
U++ 创建UI
MAYA船的建模
MVCC of Google's Fragmented Notes (Draft)
C-Eighty seven(背包+bitset)
IO process thread -> communication between processes -> day7
Redis数据库学习
Vulnhub靶机:HA_ NARAK
Use of thread pool (combined with Future/Callable)
不能比较或排序 text、ntext 和 image 数据类型
MAYA大炮建模