首页 > 小红的数组清空
头像 光电理中外范育博
发表于 2025-09-09 20:40:19
map哈希表 错误原因:没有发现数组重复,例如:1222333444555,未统计重复的序列 做法 map<int ,int>freq 统计每个数字的出现频率 对于每个数字x,如果有x-1存在,那么部分x可以接在x-1后面(免费删除) 具体来说:对于数字x,最多有min(freq[x-1 展开全文
头像 yousaegg
发表于 2026-02-09 00:13:58
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; using ll = long long; int main( 展开全文
头像 飞鸢泛惊鸿
发表于 2026-02-09 01:13:39
from collections import Counter input() nums=list(map(int,input().split())) ans=0 prev_cnt=0 prev_key=-1 cnt=Counter(nums) for i in sorted(cnt.keys()) 展开全文
头像 Yuaeb_698
发表于 2026-02-09 00:05:41
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; map<int,int>m; for(int i=0;i<n;i++){ 展开全文
头像 MrAsleeep
发表于 2026-02-09 01:47:18
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin>>n; set<int>tp; map&l 展开全文
头像 mollor
发表于 2026-02-09 02:25:21
直接模拟喵,就类似空当接龙喵,你理解的吧喵我们先排序,这样就确保了不会出现先把2放进牌组,但是后面又出现1的情况我们需要找到对于每个a[i],我们都要找到有没有a[i] - 1能接上的喵对于这样的查找,我们最好每次都能logn找到喵这样一来喵,我们选multiset就是一个最好的选择了喵玩空当接龙最 展开全文
头像 lotusor
发表于 2026-02-09 03:47:38
from collections import Counter n = int(input()) a = list(map(int,input().split())) a.sort() dic = Counter(a) k = -1 kv = -1 cnt = 0 for key,value in 展开全文
头像 小男娘
发表于 2026-02-09 10:44:12
参考铺设道路,我们对于每一个 x 计算 cnt[x]-cnt[x-1] 就做完了使用哈希表可以避免排序复杂度__gnu_pbds::gp_hash_table 比 std::unordered_map 快,并使用 splitmix64 防造数据卡 #include <cctype> #i 展开全文
头像 FoolBlade
发表于 2026-02-09 11:03:23
#include<bits/stdc++.h> using namespace std; int main(){ int n;cin>>n; vector<int> a(n+1); for(int i=1;i<=n;i++)cin&g 展开全文
头像 Night_crusing
发表于 2026-02-09 11:30:00
这个题目一开始拿到之后的思路是很明显的,就是统计连续片段的个数,但是这种思路会忽视连选数字的并行情况例如(111222这种得到的cost会是6,所以使用multiset来进行删除工作,逻辑不变,更加符合直觉。 #include<bits/stdc++.h> using namespace 展开全文

等你来战

查看全部