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

题目链接:https://www.zhixincode.com/problem/day2-2

思路:暴力枚举两个数字,拼接一块后比较,注意题目是按下标顺序删除(n - 2)个数字,n^{2}暴力最大的那项会爆long long但不会爆unsigned long long。

#include 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int maxn = 6e3 + 10;
int a[maxn];
ull add(ull a, ull b)
{
	ull t = b;
	while(t)
		a *= 10, t /= 10;
	return a + b;
}
int main()
{
	int t, Case = 1;
	cin >> t;
	while(t--)
	{
		int n;
		scanf("%d", &n);
		for (int i = 0; i < n; i++)
			scanf("%d", &a[i]);
		ull ans = 0;
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
				ans = max(ans, add(a[i], a[j]));
		printf("Case #%d: %llu\n", Case++, ans);
	}
	return 0;
}

 

你可能感兴趣的:(【思维】)