Atcoder Grand 025 - A 题解

题意:

已知a + b = n, 问 a 和 b 各个数位的和相加的最小值。

有点不好表述,解释一下样例吧,给一个数15,当a = 2, b = 13时所求最小,2的各个数位和就是2,13各个数位和是1 + 3= 4,故2 + 4 = 6为所求。

Emmm,水题实锤了

本人AC代码:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int Inf = 1e9 + 7;
const int maxn = 1e5 + 7;
queue <int> qua;
map <int, int> mp;
int n;

int main() {
    cin >> n;
    int minT = Inf;
    if(n % 10 == 0) minT = 10;
    else {
        for(int i = 1; i <= n; i++) {
            int t = i, p = n - i;
            int s1 = 0, s2 = 0;
            while(t) {
                s1 += t % 10;
                t /= 10;
            }
            while(p) {
                s2 += p % 10;
                p /= 10;
            }
            minT = min(minT, s1 + s2);
        }
    }
    cout << minT << endl;
}

猜你喜欢

转载自blog.csdn.net/ericgipsy/article/details/80577799
今日推荐