題目:要買一系列的島,島的價格已知,需要支付的總數為 2*L[fristbuy]^1 + 2*L[secondbuy]^2 + ... ,問最少支付多少。
分析:貪心,排序。直接按價值排序從大到小購買即可。
說明:╮(╯▽╰)╭。
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int L[41];
int main()
{
int t;
while (~scanf("%d",&t))
while (t --) {
int n = 0;
while (scanf("%d",&L[n]) && L[n])
n ++;
sort(L, L+n);
long long ans = 0LL, pow;
for (int i = n-1; i >= 0; -- i) {
pow = 2LL;
for (int j = n; j > i; -- j)
pow = pow*L[i];
ans += pow;
}
if (ans > 5000000)
printf("Too expensive\n");
else printf("%lld\n",ans);
}
return 0;
}