悬赏一永久关注
by MTF_Lambda_04 @ 2024-02-07 09:17:52
```
#include<bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int a[N];
void swap(int &x, int &y) {
int temp = x;
x = y;
y = temp;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int low = 0, mid = 0, high = n - 1;
int swaps = 0;
while (mid <= high) {
switch (a[mid]) {
case 1:
swap(a[low++], a[mid++]);
swaps++;
break;
case 2:
mid++;
break;
case 3:
swap(a[mid], a[high--]);
swaps++;
break;
}
}
swaps -= low;
printf("%d\n", swaps);
return 0;
}
```
by Minecraft_wjr @ 2024-02-07 09:39:27
@[MTF_Birdwatchers](/user/898114) hack:
```
4
3 2 1 1
```
by UYHW @ 2024-02-07 10:59:53
@[UYHW](/user/252567) 谢谢知道问题了
by MTF_Lambda_04 @ 2024-02-07 11:18:47