题解:P12696 [KOI 2022 Round 2] 原位卡片
2025.6.10 修改了错别字。
题解:P12696 [KOI 2022 Round 2] 原位卡片
一道很简单的题。
思路简述
用变量
直接遍历整个
代码呈现
C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,t,cnt;
signed main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1,j=1;i<=n;i++){
cin>>t;
if(t==j) j++;//如果可以作为原位状态的一个数则j加一
else cnt++;//否则要删掉,cnt加一
}
cout<<cnt;
return 0;
}