当前位置:网站首页>[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;
}
边栏推荐
- Modeling of the MAYA ship
- Cannot compare or sort text, ntext, and image data types
- 400 times performance improvement 丨 swap valuation optimization case calculation
- 【Dynamic type detection Objective-C】
- MAYA船的建模
- 【深度学习实践(一)】安装TensorFlow
- Mysql 死锁和死锁的解决方案
- 小本创业者的致胜法宝!
- An IP conflict is reported after installing the software on a dedicated computer terminal
- 利用Jenkins的持续集成
猜你喜欢
随机推荐
A small problem with mysql using the in function
Illegal key size 报错问题
GAN generates anime avatar Pytorch
After working for 3 years, I recalled the comparison between the past and the present when I first started, and joked about my testing career
【 LeetCode 】 235. A binary search tree in recent common ancestor
TRACE32——外设寄存器查看与修改
VXE-Table融合多语言
JS实现从照片中裁切自已的肖像
2022 crane driver (limited bridge crane) exam question bank and simulation test
Modeling of the MAYA ship
400 times performance improvement 丨 swap valuation optimization case calculation
小本创业者的致胜法宝!
游戏模拟器成了外挂帮凶,灰产对抗再升级
唤醒手腕 - 微信小程序、QQ小程序、抖音小程序学习笔记(更新中)
TCP sticky packet unpacking problem + solution
【Dynamic type detection Objective-C】
本地能ping通虚拟机,虚拟机ping不通本地
Basic introduction of stack and queue and C language implementation of functions such as creation, destruction, entry and exit, counting the number of elements, viewing elements, etc., as well as stac
MongoDB 语法大全
Stored procedure writing experience and optimization measures









