首页 > 试题广场 >

小红的不动点分配

[编程题]小红的不动点分配
  • 热度指数:354 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 1024M,其他语言2048M
  • 算法知识视频讲解
\hspace{15pt}小红拿到了 2\times n 个元素,现在她想将这些元素划分为两组(每组恰好 n 个元素),且两组内部的顺序均可任意重排。
\hspace{15pt}她想知道,这两个数组的不动点数量之和最多是多少,请你帮帮她。

【名词解释】
\hspace{15pt}不动点:定义整数 i\left(1\leqq i \leqq m \right) 是长度为 m 的数组 \{a_1,a_2,\dots,a_m\} 的一个不动点,当且仅当满足 a_i = i

输入描述:
\hspace{15pt}第一行输入一个整数 n \left(1 \leqq n \leqq 2\times10^5 \right)
\hspace{15pt}第二行输入 2\times n 个正整数 a_1,a_2,\dots,a_{2\times n} \left(1\leqq a_i \leqq 2\times 10^5 \right),代表数组中的元素。


输出描述:
\hspace{15pt}输出一个整数,代表两个数组的不动点数量之和的最大值。
示例1

输入

3
1 1 4 5 1 4

输出

2
示例2

输入

1
1 2

输出

1
头像 ddb酱
发表于 2025-11-17 10:54:49
#include <bits/stdc++.h> using namespace std; #define endl "\n" using vi = vector<int>; using msi = multiset<int>; void s 展开全文
头像 Drink0318
发表于 2025-12-09 14:45:46
import sys from collections import Counter n = int(input()) lst = list(map(int,input().split())) # 统计每个数字的出现次数 counter = Counter(lst) res=0 for key,va 展开全文
头像 l_ss
发表于 2025-11-28 00:39:23
#include <bits/stdc++.h> using namespace std; map<int, int>mp; int main() { int n; cin >> n; vector<int>a(2 * n + 展开全文
头像 牛客用户098471297
发表于 2025-11-28 08:46:27
#include<bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define quick ios::sync_with_stdio(false);cin.tie(0);cout.t 展开全文
头像 tartarns_yan
发表于 2025-12-08 08:22:05
#include <bits/stdc++.h> using namespace std; int a[400005]; map<int, int>mapp; int main() { int n, res = 0; cin >> n; f 展开全文
头像 自由的风0450
发表于 2025-11-26 12:57:10
#include <iostream> #include<vector> #include<unordered_map> using namespace std; int main() { ios::sync_with_stdio(false); 展开全文
头像 Furina_love
发表于 2025-11-15 16:37:01
贪心即可处理,对于满足x<n的x,只要出现了就是一个不动点,最多作为不动点两次 #include <bits/stdc++.h> using namespace std; using ll = long long; const int OvO = 0; int main() { 展开全文