标签:c
4 1 3 1 2 1
3Hintif WLD deletes a 3, the numbers remain is [1,1,2],he‘ll get 2 different numbers. if WLD deletes a 2, the numbers remain is [1,1,3],he‘ll get 2 different numbers. if WLD deletes a 1, the numbers remain is [1,2,3],he‘ll get 3 different numbers.题意:从n个数中删k个数,求剩下的数中最多有多少个不同的数代码:#include<cstdio> #include<set> using namespace std; int a[105]; int main() { set<int> st; int n; while(scanf("%d",&n)==1) { st.clear(); for(int i=0;i<n;i++) { scanf("%d",&a[i]); st.insert(a[i]); } int cnt=n-st.size(); int k; scanf("%d",&k); if(k<=cnt) printf("%d\n",st.size()); else printf("%d\n",st.size()-k+cnt); } return 0; }
标签:c
原文地址:http://blog.csdn.net/xky1306102chenhong/article/details/45320611