--- title: "收集卡牌" created: 2025-11-28 tags: - 算法 --- # 收集卡牌 ## 题目 [收集卡牌](https://www.acwing.com/problem/content/description/4504/) ![[image-1836dda1.png]] ## 思路分析 种类与个数的问题 双指针和队列里见过很多次了 维护每种的个数 再维护种类的数量 可以用unordered\_map也可以直接用值做下标计数 ## 代码实现 ```cpp #include using namespace std; const int N=100010; int cnt[N]; int n,m; int main() { cin>>n>>m; int total=0; while(m--){ int x; cin>>x; if(!cnt[x]) total++; cnt[x]++; if(total==n){ cout<<1; for(int i=1;i<=n;i++){ if(--cnt[i]==0) total--; } } else cout<<0; } return 0; } ``` ```cpp #include using namespace std; unordered_map h; int n,m; int main() { cin>>n>>m; int total=0; while(m--){ int x; cin>>x; if(!h[x]) total++; h[x]++; if(total==n){ cout<<1; for(int i=1;i<=n;i++){ if(--h[i]==0) total--; } } else cout<<0; } return 0; } ``` ## 同类题型 ## 视频讲解 --- ⬅️ [[商品总类|商品总类]] 🏠 [[00-刷题理模型]] ➡️ [[最大数量|最大数量]]