zoukankan      html  css  js  c++  java
  • P1540 机器翻译

    用队列维护单词进入内存的时间顺序,并根据题目所给的内存限制动态调整内存区域存储的单词,并对内存中包括的单词做标记
    注意:题面说如果内存中已经存在这个单词就不要到外存去找了,相应的不需要把这个单词放到内存里。
    复杂度:(O(n))

    #include<iostream>
    
    using namespace std;
    
    const int N = 1010;
    
    int st[N];
    int m, n;
    int q[N], hh, tt = -1;
    
    int main(){
        cin >> m >> n;
        
        int res = 0;
        while(n --){
            int x;
            
            cin >> x;
            
            if(st[x]) continue;
            res ++;
            while(tt - hh + 1 > m - 1) st[q[hh ++]] --;
            st[x] ++;
            q[++ tt] = x;
        }
        
        cout << res;
        
        return 0;
    }
    
  • 相关阅读:
    python3第六天
    python3第五天
    python3第四天
    python3 第三天
    python3第二天
    python3(2)
    python3(1)
    网络通信 & 初识socket
    python中包的语法
    模块语法
  • 原文地址:https://www.cnblogs.com/tomori/p/13854160.html
Copyright © 2011-2022 走看看