Lấy táo
Có 𝑁 quả táo được xếp thành một hàng ngang. Các quả táo được đánh số thứ tự từ 1 đến 𝑁 (hướng từ trái sang phải). Quả táo thứ i có khối lượng ai.
Yêu cầu: Bạn hãy chọn các quả táo sao cho:
Dữ liệu cho trong file Apple.Inp gồm:
Kết quả ghi ra file Apple.Out là số táo nhiều nhất có thể chọn được.
Ví dụ:
APPLE.INP
5
1 4 4 3 2
APPLE.OUT
2
c++,mảng 1 chiều
Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
using namespace std;
int n, a[1000005], d = 0, s;
map < int, long long > b;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[a[i]]++;
}
for (int i = 1; i <= n; i++) {
s = b[a[i]];
d = max(d, s);
}
cout << d;
return 0;
}
# $\color{black}{\text{le}}$$\color{gray}{\text{duc}}$$\color{darkgray}{\text{trung}}$$\color{lightgray}{\text{anh}}$
Hãy giúp mọi người biết câu trả lời này thế nào?
#include <bits/stdc++.h>
#define ll long long
#define str string
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define MAXN 1000000
#define INPUT freopen("APPLE.INP","r",stdin);
#define OUTPUT freopen("APPLE.OUT","w",stdout);
using namespace std;
int main() {
INPUT
OUTPUT
FAST
ll n,m,dem=0;
cin>>n;
map<ll,ll> a;
for (ll i=0;i<n;i++) {
cin>>m;
dem=max(dem,++a[m]);
}
cout<<dem;
return 0;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin