当前位置:网站首页>[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;
}
边栏推荐
猜你喜欢

2022 Fusion Welding and Thermal Cutting Operation Certificate Exam Questions and Mock Exams

MAYA船的建模

MVCC of Google's Fragmented Notes (Draft)

Tencent Internship Summary

利用Jenkins的持续集成

Support touch screen slider carousel plugin

二叉树进阶复习1

Jmeter永久设置中文界面

Flink Learning 12: DataStreaming API

在anaconda Promat界面import torch通过,在jupyter notebook中报错的问题(仅提供思路理解!)
随机推荐
国家强制性灯具安全标准GB7000.1-2015
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
C# FileSystemWatcher
691. 立方体IV
不能比较或排序 text、ntext 和 image 数据类型
谷歌零碎笔记之MVCC(草稿)
MobileNetV1架构解析
unity 头发的渲染
Hash these knowledge you should also know
Algorithm Supplements Fifteen Complementary Linked List Related Interview Questions
Bluetooth gap protocol
网络安全研究发现,P2E项目遭遇黑客攻击只是时间问题
Access Denied: "microsoft.web.ui.webcontrols" workaround
外企Office常用英语
JS实现从照片中裁切自已的肖像
Shiny02---Shiny exception solution
[instancetype type Objective-C]
双向循环带头链表
[Shanghai] Hiring .Net Senior Software Engineer & BI Data Warehouse Engineer (Urgent)
SVG大鱼吃小鱼动画js特效