题解 | 小橙的完美序列

小橙的完美序列

https://www.nowcoder.com/practice/ee33ec4d445d4ca38e89811e35c77ccd

#include <iostream>
#include<unordered_map>
using namespace std;
unordered_map<int,int> map;//unordered_map查找更快
int main() 
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;//输入a[i]
        map[x^i]++;//对映的位置++
    }
    int maxcnt=-1e9;//找到最多的次数
    for(auto x:map)
    {
        maxcnt=max(maxcnt,x.second);
    }
    int ans=n-maxcnt;//将剩下的都改为出现次数最多的
    cout<<ans<<endl;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

回家当保安:今天刚过字节一面,接佬的好运
我的求职进度条
点赞 评论 收藏
分享
04-08 21:39
已编辑
Java
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务