CCPC-Wannafly Winter Camp Day2 (Div2, onsite) A Erase Numbers II 暴力

A-Erase Numbers II
题解:开始瞎几把想了个假的贪心,贪最大值,果断wa了3发,发现是个假策略并算了算复杂度发现直接n方暴力求出两两组合最大值就可以过了

#include
#include
#define ull unsigned long long
using namespace std;
const int maxn = 6e3 + 10;
ull a[maxn];
void slove(ull &a, ull b){
    while(b){
        a *= 10;
        b /= 10;
    }
}

int main(){
    int t, t1 = 1;
    scanf("%d", &t);
    while(t--){
        int n;
        scanf("%d", &n);
        for(int i = 0; i < n; ++i)
            cin >> a[i];
        ull ans = 0, temp;
        for(int i = 0; i < n - 1; ++i){
            for(int j = i + 1; j < n; ++j){
                temp = a[i];
                slove(temp, a[j]);
                ans = max(ans, temp + a[j]);
            }
        }
        cout << "Case #" << t1++ << ": " << ans << endl;
    }
    return 0;
}

你可能感兴趣的:(题解,暴力,2019,Wannafly,Winter,Camp)