洛谷题单P540,机器翻译 队列queue<int>

洛谷题单P540,机器翻译

复制代码
#include<bits/stdc++.h>
using namespace std;
int Hash[1003] = { 0 };//利用哈希检查内存中有没有单词,hash[i]=1,表示单词i在内存中
queue<int>mem;         //用队列模拟内存
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n, m,cnt=0;//cnt表示查字典的次数
    cin >> m >> n;
    while (n--){
        int en; cin >> en;//输入一个英文单词
        if (!Hash[en]){//如果内存中没有这个单词
            ++cnt;
            mem.push(en);//单词入队列,放到队列尾部
            Hash[en] = 1;//记录内存中这个单词
            while (mem.size() > m){//内存满了
                Hash[mem.front()] = 0;//从内存中删去单词
                mem.pop();//从队尾去掉
            }
        }
    }
    cout << cnt<<"\n";
    return 0;
}
相关推荐
vivo互联网技术11 小时前
未来,什么才是 AI“正确的使用方式”
人工智能·ai编程
甲维斯12 小时前
豆包Seed2.1Pro编程能力测试!
人工智能·ai编程
Zy宇12 小时前
从养 OpenClaw 到养社区 AI:一套 Multi-Agent 社区的设计思路
人工智能·ai
雪隐13 小时前
个人电脑玩AI-06让5060 Ti给你打工——Qwen3.6-35B-A3B + LM Studio + openWebUI
人工智能·后端
得物技术13 小时前
从表单到 Agent:得物社区活动搭建的 AI 实践之路
人工智能·架构·agent
Weigang13 小时前
给 Agent 接入 Qdrant 前,先写清楚检索合同
人工智能
字节跳动数据库13 小时前
文章分享——庖丁解牛-图解查询分析和调优利器Optimizer Trace
人工智能·程序员
以和为贵13 小时前
前端手写 RAG 踩坑实录:四个让检索"翻车"的坑
前端·人工智能·面试
何时梦醒13 小时前
深入理解 LLM Tokenization:从文本分词到语义向量化的完整旅程
人工智能
冬哥聊AI13 小时前
阿里二面:8K Token 撑住 100 轮对话,你的分层记忆架构怎么设计?
人工智能