Acwing第56场周赛报告
得分情况
T1:AC
T2:AC
T3:0
T4:AC
错题分析
T3
对于一个k位小数,我们只要乘上k个x,就可以把这个小数全部转化成整数。
那么,对于p/q,只要(p/q) * x^k 是整数,就说明p/q的小数可以用k个有限小数的形式来表示。
代码
T1
#include <bits/stdc++.h>
using namespace std;
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int num[n];
for (int i = 0; i < n; i ++) cin >> num[i];
int res = 0;
int xf[101];
memset(xf, 0, sizeof(xf));
for (int x: num){
xf[x] ++;
res = max(res, xf[x]);
}
cout<<res<<endl;
return 0;
}
T2
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int a[200100];
int hax[N];
int main(){
int n, k;
cin >> n >> k;
for (int i = 0; i < n;i++){
cin >> a[i];
hax[a[i]]++;
}
sort(a, a + n);
int ans = 0;
for (int i = 0;i < n - 1;i++){
if (!hax[a[i]] || a[i] == a[i + 1]){
continue;
}
if (a[i + 1] - a[i] <= k){
ans += hax[a[i]];
hax[a[i]] = 0;
}
}
cout <<n-ans<<endl;
return 0;
}
T4
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> PII;
const int N = 50010;
int n;
PII cow[N];
int main(){
scanf("%d", &n);
for (int i = 0; i < n; i ++ ){
int s, w;
scanf("%d%d", &w, &s);
cow[i] = {w + s, w};
}
sort(cow, cow + n);
int res = -2e9, sum = 0;
for (int i = 0; i < n; i ++ ){
int s = cow[i].first - cow[i].second, w = cow[i].second;
res = max(res, sum - s);
sum += w;
}
printf("%d\n", res);
return 0;
}