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

Category: Violence Data Range

Portal: https://www.zhixincode.com/contest/8/problem/A?problem_id=122

ideas

Delete n-2 numbers from n numbers, that is, there are only two numbers left. The possible situation is 6000×5999/2=18e6
in ×n(6000) complexity ok Direct violence, just find the largest number

There are pits: when two numbers are spelled together, they are two 1e9 numbers, which require 19 bits.
This is beyond the range of ll (a little more than 18 bits), and all must be unsigned ull

AC code

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll a[6005];
int main()
{
    int t,n;
    cin>>t;
    for(int k=1;k<=t;k++)
    {
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        ll maxx=0;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                //拼起来
                ll f=a[i],b=a[j];
                while(b)
                {
                    f*=10;
                    b/=10;
                }
                f+=a[j];
                maxx=max(maxx,f);
            }
        }
        cout<<"Case #"<<k<<": "<<maxx<<endl;
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325687186&siteId=291194637