您的位置:首页 > 其它

UVa 11824 - A Minimum Land Price

2015-12-18 17:59 176 查看
題目:要買一系列的島,島的價格已知,需要支付的總數為 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
) && L
)
			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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: