• luogu1540 [NOIp2011]机器翻译 (队列)


     1 #include<bits/stdc++.h>
     2 #define pa pair<int,int>
     3 #define CLR(a,x) memset(a,x,sizeof(a))
     4 using namespace std;
     5 typedef long long ll;
     6 const int maxn=1010,maxm=110;
     7 
     8 inline ll rd(){
     9     ll x=0;char c=getchar();int neg=1;
    10     while(c<'0'||c>'9'){if(c=='-') neg=-1;c=getchar();}
    11     while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    12     return x*neg;
    13 }
    14 
    15 queue<int> q;
    16 int N,M;
    17 bool ins[maxn];
    18 
    19 int main(){
    20     //freopen("","r",stdin);
    21     int i,j,k,ans=0;
    22     M=rd(),N=rd();
    23     for(i=1;i<=N;i++){
    24         int x=rd();
    25         if(!ins[x]){
    26             ans++;
    27             if(q.size()>=M){
    28                 ins[q.front()]=0;q.pop();
    29             }
    30             ins[x]=1;q.push(x);
    31         }
    32     }
    33     printf("%d
    ",ans);
    34     return 0;
    35 }
  • 相关阅读:
    11、旋转图像
    10、有效的数独
    9、两数之和
    8、移动零
    6、两个数组的交集 II
    7、加一
    5、只出现一次的数字
    3、旋转数组
    spring快速复习
    mybatis XML SQL基本配置
  • 原文地址:https://www.cnblogs.com/Ressed/p/9735666.html
Copyright © 2020-2023  润新知