# 2013四川省赛（G，K）

G - Good Numbers
K - Kia’s Calculation

# G - Good Numbers

num([a, b]) = num([0, b]) - num([0, a- 1])。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define db1(x) cout << #x << " = " << x << endl;
const double eps = 1e-6;
const int N = 2e3 + 10;
const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1} };
void FAST() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}

ll dsum(ll x) {
ll sum = 0;
while(x) {
sum += (x % 10);
x /= 10;
}
return sum;
}

ll cal(ll x) {
ll ans = x / 10;
for (ll i = x / 10 * 10; i <= x; ++ i) {
ll sum = dsum(i);
if(sum % 10 == 0) return ans + 1;
}
return ans;
}

void solve(int T) {
ll a, b; scanf("%lld%lld", &a, &b);
ll ans = cal(b) - cal(a - 1);
printf("Case #%d: %lld\n", T, ans);
}

int main() {
//    FAST();
int cnt = 0;
int T; scanf("%d", &T); while(T--) solve(++ cnt);
return 0;
}


# K - Kia’s Calculation

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define db1(x) cout << #x << " = " << x << endl;
const int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1} };
void FAST() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
const int N = 1e6 + 10;
char s1[N], s2[N];
int a[11], b[11], c[N];

void solve(int T) {
scanf("%s %s", s1, s2);
int len = strlen(s1);
if(len == 1) {
int ans = s1[0] - '0' + s2[0] - '0';
ans %= 10;
printf("Case #%d: %d\n", T, ans);
return ;
}
for (int i = 0; i < len; ++ i) a[s1[i] - '0'] ++, b[s2[i] - '0'] ++;
int mx = -1, pi, pj;
for (int i = 1; i <= 9; ++ i) {
if(!a[i]) continue;
for (int j = 1; j <= 9; ++ j) {
if(!b[j]) continue;
int p = (i + j) % 10;
if(p > mx) {mx = p; pi = i; pj = j; }
}
}
c[0] = 0;
c[++c[0]] = mx;
a[pi] --; b[pj] --;
for (int i = 9; i >= 0; -- i) {
for (int j = 0; j <= 9; ++ j) {
if(!a[j]) continue;
int tmp = (i - j + 10) % 10;
if(b[tmp]) {
int mi = min(a[j], b[tmp]);
a[j] -= mi; b[tmp] -= mi;
while(mi -- ) c[++c[0]] = i;
}
}
}
int s = 1;
while(c[s] == 0 && s <= c[0]) ++ s;
s = min(s, c[0]);
printf("Case #%d: ", T);
for (int i = s; i <= c[0]; ++ i) printf("%d", c[i]);
printf("\n");
}

int main() {
//    FAST();
int cnt = 0;
int T; scanf("%d", &T); while(T--) solve(++ cnt);
return 0;
}


©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客