算法:模拟
- 处理到每头牛的位置时,看看它是否与上次的位置相同
- 相同就跳过,不同就更新位置,同时结果+1
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 11;
int n;
int b[N];
int main() {
cin >> n;
int res = 0;
memset(b, -1, sizeof b);
for (int i = 0; i < n; i ++) {
int x, y; cin >> x >> y;
if (b[x] != -1 && b[x] != y) res ++, b[x] = y;
else b[x] = y;
}
cout << res;
return 0;
}