题目链接:Dashboard - Codeforces Round 861 (Div. 2) - Codeforces
解题思路:大于100就直接输出最大值,小于的话就暴力一下。
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,(rt<<1)|1
typedef long long ll;
using ull = unsigned long long;
const int mx = 1e5 + 10;
const int mod = 1e9 + 7;
int main() {
auto solve = [](int x) {
int mi = 100, ma = -1;
while (x) {
int v = x % 10;
ma = max(ma, v);
mi = min(mi, v);
x /= 10;
}
return ma - mi;
};
int t;
scanf("%d", &t);
while(t--) {
int l, r;
scanf("%d%d", &l, &r);
if (r - l >= 100) {
int v = l / 100 * 100 + 90;
if (v < l)
printf("%d\n", v + 100);
else
printf("%d\n", v);
continue;
}
int ans = -1,p;
while (l <= r) {
int val = solve(l);
if (ans < val) {
ans = val;
p = l;
}
l++;
}
printf("%d\n", p);
}
return 0;
}
解题思路:按列进行排序,然后算一下每个数的正负值贡献
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,(rt<<1)|1
typedef long long ll;
using ull = unsigned long long;
const int mx = 3e5 + 10;
const int mod = 1e9 + 7;
vector <int> vec[mx];
int main() {
auto solve = [](int x) {
int mi = 100, ma = -1;
while (x) {
int v = x % 10;