2 solutions
-
0
y1s1题目看了很久都没看懂,最后还是看的题解才看懂到底要干嘛
简单来说就是,有一堆数字,找出数组中数字相同的个数的最大值,相同的数字可以重叠,最后还要计算重叠之后的全部的数字的个数
#include<bits/stdc++.h> using namespace std; int n,ans; int num[1005]; int main() { std::ios::sync_with_stdio(false); cin>>n; for(int i = 0;i < n; i++) cin>>num[i]; sort(num,num+n); int sum = 1,cnt = 1; for(int i = 1; i < n; i++){ if(num[i] == num[i-1]) cnt++; else{ cnt = 1; sum++; } ans=max(ans,cnt); } cout<<ans<<" "<<sum; return 0; }
Information
- ID
- 1960
- Time
- 2000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 32
- Accepted
- 15
- Uploaded By