bestcoder Delete
生活随笔
收集整理的這篇文章主要介紹了
bestcoder Delete
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
問題描述 wld有n個數(shù)(a1,a2,...,an),他希望進(jìn)行k次刪除一個數(shù)的操作,使得最后剩下的n?k個數(shù)中有最多的不同的數(shù),保證1≤n≤100,0≤k<n,1≤ai≤n(對于任意1≤i≤n) 輸入描述 多組數(shù)據(jù)(最多100組)
對于每組數(shù)據(jù):
第一行:一個數(shù)n表示數(shù)的個數(shù)
接下來一行:n個數(shù),依次為a1,a2,…,an
接下來一行:一個數(shù)k表示操作數(shù) 輸出描述 對于每組數(shù)據(jù):
輸出最多剩下的不同的數(shù)的個數(shù) 輸入樣例 4
1 3 1 2
1 輸出樣例 3 Hint 如果刪去第一個1:
在[3,1,2]中有3個不同的數(shù)
如果刪去3:
在[1,1,2]中有2個不同的數(shù)
如果刪去第二個1:
在[1,3,2]中有3個不同的數(shù)
如果刪去2:
在[1,3,1]中有1個不同的數(shù) #include <iostream>
#include <algorithm>
using namespace std;
struct node
{int data;int count;
};
int main()
{int n;while(cin>>n){int num[110],k,cnt=0,chong=0;node p[110];for(int i=0;i<n;i++){cin>>num[i];p[i].count=0;}sort(num,num+n);cin>>k;p[0].data=num[0];p[0].count=1;for(int i=1;i<n;i++){if(num[i]==p[cnt].data)(p[cnt].count)++;else{chong=chong+p[cnt].count-1;cnt++;p[cnt].data=num[i];p[cnt].count++;}}chong=chong+p[cnt].count-1;if(k<=chong)cout<<cnt+1<<endl;elsecout<<(cnt+1)-(k-chong)<<endl;}return 0;
}
轉(zhuǎn)載于:https://www.cnblogs.com/MisdomTianYa/p/6581767.html
總結(jié)
以上是生活随笔為你收集整理的bestcoder Delete的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 归档模式管理
- 下一篇: Individual Project