☘前言☘
今日份水题开始。希望有想要提高的同学跟我们一起来刷题0.0
4.8日每日一题——[NOIP2010 提高组] 机器翻译
🧑🏻作者简介:一个从工业设计改行学嵌入式的年轻人
✨联系方式:2201891280(QQ)
⏳全文大约阅读时间: 20min
解题思路
本来以为是内存替换策略的LRU算法,好家伙,原来是FIFO算法,我理解错了,是我傻了。直接一个循环队列就完事了呗?
#include <stdio.h>
#include <string.h>
unsigned char hash[1005];
short zhan[105];
int main(){
int m, n, ans = 0, head = 0, tail = 0;
memset(hash,0,sizeof(hash));
scanf("%d %d",&m, &n);
for(int i = 0;i < n;++i){
int tmp;
scanf("%d", &tmp);
if(hash[tmp]) continue;
hash[tmp] = 1;
if(head == tail && i ) hash[zhan[tail]] = 0,tail = (tail + 1) % m; //删除标记。出队
zhan[head] = tmp, head = (head + 1) % m; //入队
ans++;
}
printf("%d",ans);
return 0;
}
挺好,不改了。
📑写在最后
今天就这样,明日再见0.0