题解:P17589 Antithese
_priority_queue_ · · 题解
本蒟蒻的第一篇题解,趁着比赛完赶紧来发。
这是一道很简单的贪心题,只需要稍微想一下就能想出贪心策略,贪心策略:对于每一个x,如果它对应的位置是1的话,就直接跳过,反之,则把它变为1,接着1的数量增加,把这个位置的状态改变。
AC CODE
#include <bits/stdc++.h>
using namespace std;
long long ans,n,m,a[10000000],x;
char t;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++){
cin >> t;
a[i] = t - '0';
ans += a[i];
}
for(int i = 1;i <= m;i++){
cin >> x;
if(a[x] == 0){
ans++;
a[x] = 1;
}
}
cout << ans;
return 0;
}
写的有点少,感觉也没啥好写的,不喜勿喷,求管理员过