标签:bsp amp cst blog main include space 存在 cstring
http://codeforces.com/problemset/problem/729/E
存在的数必须连续,若不连续,从最后选人来补,注意根不是0和其他点是0的情况。
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int n,s,num[200005] = {0}; int main() { int ans = 0,t = 0; scanf("%d%d",&n,&s); for(int i = 1;i <= n;i++) { int x; scanf("%d",&x); if(i == s && x != 0) ans++; else if(i != s && x == 0) { t++; ans++; } else num[x]++; } int sum = 1; for(int i = 1;i < n;i++) { if(sum >= n) break; if(!num[i]) { if(t) t--; else ans++; sum++; } else sum += num[i]; } printf("%d\n",ans); return 0; }
标签:bsp amp cst blog main include space 存在 cstring
原文地址:http://www.cnblogs.com/zhurb/p/6104865.html