题解 | #机器翻译#
机器翻译
https://ac.nowcoder.com/acm/problem/16589
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
int ans = 0;
int sum = 0;
Queue<Integer>queue = new LinkedList<Integer>();
for(int i = 0;i<n;i++){
int danci = sc.nextInt();
boolean flag = false;
for(int chaxun:queue){
if(chaxun==danci){
flag = true;
break;
}
}
if(!flag){
if(ans==m){
sum+=1;
queue.poll();
queue.add(danci);
}else{
sum+=1;
ans = ans+1;
queue.add(danci);
}
}
}
System.out.print(sum);
}
}