M: Olympic Parade
可能这个题目的难度在于理解题意吧
就是问你给你N个数字,问这N个数字出现的哪个数字次数不能被K整除
那当然是选择……map啦
#include <bits/stdc++.h>
#define N 10100
#define INF 0x3f3f3f3f
#define LL long long
#define mem(a,n) memset(a,n,sizeof(a))
#define fread freopen("in.txt","r",stdin)
#define fwrite freopen("out.txt","w",stdout)
using namespace std;
int main()
{
ios::sync_with_stdio(false);
map<int,int> ans;
int t,n,k;
cin>>t>>k;
while(t--){
cin>>n;
ans[n]++;
}
map<int,int>::iterator it1=ans.begin(),it2=ans.end();
while(it1!=it2){
if(it1->second%k){
cout<<it1->first<<endl;
break;
}++it1;
}
return 0;
}
本文介绍了一个利用C++ map数据结构解决特定算法问题的方法。该问题要求找出一组给定数字中,出现次数不能被特定整数K整除的数字。通过遍历输入并使用map记录每个数字出现的频率,可以有效地找到满足条件的数字。
575

被折叠的 条评论
为什么被折叠?



