3 条题解
-
0Dream_Runner LV 4 @ 2017-08-21 11:52:40
stl大法好
#include<iostream> #include<set> using namespace std; set<int>a; int main(){ int n,k,cnt=0; cin>>n>>k; for(int i=1;i<=n;++i){ int t; cin>>t; if(a.count(t)==1); else a.insert(t),++cnt; } int t=n-cnt-k; if(t>0)t=0; cout<<cnt+t; return 0; }
-
02017-08-11 10:46:17@
筛掉重复的,计数,取\(min\{ n-k,totleft \}\)
#include<cstdio> #include<algorithm> const int MAXN=100000+5; int n,k,totrep,nums[MAXN],totleft;bool disabled[MAXN]; int main() { scanf("%d %d",&n,&k); for(int i=1;i<=n;i++) scanf("%d",&nums[i]); std::sort(nums+1,nums+n+1); for(int i=1;i<n;i++) if(nums[i]==nums[i+1]) disabled[i+1]=1; for(int i=1;i<=n;i++) if(!disabled[i]) totleft++; if(totleft>n-k) printf("%d",n-k); else printf("%d",totleft); return 0; }
-
02017-08-11 10:30:40@
#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <iostream> #include <vector> #include <set> #include <map> #include <algorithm> using namespace std; const int max_n = 1e5 + 10; int n, k, a[max_n]; int main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); int multi = 0; for (int i = 2; i <= n; i++) if (a[i] == a[i - 1]) multi++; if (k <= multi) cout << n - multi << endl; else cout << n - multi - (k - multi) << endl; }
- 1
信息
- 难度
- 4
- 分类
- (无)
- 标签
- 递交数
- 19
- 已通过
- 14
- 通过率
- 74%
- 上传者