题号:1540
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | #include<bits/stdc++.h> using namespace std; int m, n; int head = 0, tail = 0; int arr[105]; int cnt; int main(){ ios::sync_with_stdio(false); cin >> m >> n; m++; for (int i = 0; i < m; i++){ arr[i] = -1; } for (int i = 1; i <= n; i++){ int word; cin >> word; bool flag = false; for (int i = head; i != tail; i = (i + 1) % m){ if (arr[i] == word){ flag = true; break; } } if (!flag){ if (head == (tail + 1) % m)head = (head + 1) % m; cnt++; arr[tail] = word; tail = (tail + 1) % m; } } cout << cnt; } |