import java.util.Scanner; public class Main { public static void main(String args[]) throws Exception { Scanner scanner = new Scanner(System.in); while (scanner.hasNextLine()) { // 输入内存数m、单词总数n String str = scanner.nextLine(); String[] kd = str.split(" "); int m = Integer.parseInt(kd[0]); int n = Integer.parseInt(kd[1]); // 输入单词 str = scanner.nextLine(); String[] numstr = str.split(" "); int[] Array = new int[numstr.length]; for (int i = 0; i < numstr.length; i++) { Array[i] = Integer.parseInt(numstr[i]); } // 输出外存查找次数 fun(Array, m); break; } } public static void fun(int[] Array, int m) { int[] Memery = new int[m]; int cnt = 0;// 查找外存次数 int currentMemryLength = 0; for (int i = 0; i < Array.length; i++) { if (find(Memery, currentMemryLength, Array[i])) { continue; } else { cnt++; if (currentMemryLength < Memery.length) { Memery[currentMemryLength++] = Array[i]; } else { for (int j = 1; j < Memery.length; j++) { Memery[j - 1] = Memery[j]; } Memery[Memery.length - 1] = Array[i]; } } } System.out.println(cnt); } public static boolean find(int[] Memery, int currentMemryLength, int word) { for (int i = 0; i < currentMemryLength; i++) { if (Memery[i] == word) { return true; } } return false; } } /************************************************************** Problem: 2296 User: admin Language: Java Result: Accepted Time:3752 ms Memory:40768 kb ****************************************************************/