R - A Minimum Land Price

普吉岛购地策略
本文介绍了一种在预算限制下,在普吉岛购买多块土地的最优策略。通过算法实现,确保按照土地价格的增长率购买最昂贵的土地,从而达到最小化总支出的目的。

Subject

      Managerof ACM-ICPC Thailand Contest Council is planning to buy lands in Phuket tobuild the office building for national programming skill camp and programmingcontest that will be held on Phuket regularly in the future. The land price inPhuket is becoming more expensive in every year. The price increases in theexponential growth curves by a factor of year. If the land i whose initial costis Li bought in t years from now, its price will be 2x(Li) t . All land pricesare different. ACM-ICPC can buy only one land per year. You have to help themanager to buy the lands at lowest price within the budget of 5,000,000millions baht. For example, if we want to buy 3 lands with costs 7, 2 and 10 in3 consecutive years, the total price will be calculated as follow.

                                                                       (2× 7) + (2 × 2^ 2 ) + (2 × 10^3 ) = 2022 millions baht 


Input

     First line of the input contains an integer T(1 ≤ T ≤ 10), the number of test cases. Each test case contains integer Liwhich is the cost of land in million baht. There are less than 40 lands in eachtest case. The line contains ‘0’ (zero) indicates the end of each test case.


Output

     Foreach test case, print out the minimum price for purchasing all lands. If thetotal price exceeds the budget (5,000,000 millions baht), print out ‘Tooexpensive’.

**************************************************************************************************************************

SampleInput

3

7

2

10

0

20

29

31

 0

42

41

40

37

 20

 0

**************************************************************************************************************************

SampleOutput

134

17744

Tooexpensive

**************************************************************************************************************************

题目大意就是:

       普吉岛的土地价格每年都在上涨。价格指数增长曲线在一年中的增长。如果这块土地的初始成本是Li从现在开始的几年里,它的价格是2x(Li)

的。预算五百万泰铢。


输入

       第一行包含一个整数T(1≤T≤10),测试用例的数量。每个测试用例 包含整数Li,这是百万泰铢的土地成本。每项测试的土地少于40个

的情况。该行包含“0”(零)表示每个测试用例的结束。


输出

      对于每个测试用例,打印出购买所有土地的最低价格。如果总价格超过预算(500万泰铢),打印出来“太贵了”。

**************************************************************************************************************************

    思路就是把贵的土地先买,便宜的之后买,因为他按照指数形式增长,所以我们先买贵的。


代码如下:

   

#include<iostream>  
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
using namespace std;

long long int fre[45];

bool cmp(long long int n,long long int m)
{
	return n>m;
}

int main()  
{  
  int n;
  scanf("%d",&n);
  while(n--)
  {
  	int t=0;
  	for(int i=0;;i++)
  	{
  		scanf("%lld",&fre[i]);
  		if(fre[i]==0) break;
  		else t++;
  	}
  	sort(fre,fre+t,cmp);
  	long long int ans =0;
  	for(int i=0;i<t;i++)
  	{
  		long long u = 2;
  		for(int j=0;j<i+1;j++)   //增长速度的次方,
  		{
  			u = u*fre[i];
  		}
  		ans+=u;
  	}
  	if(ans>5000000)
  	{
  		printf("Too expensive\n");
  	}else{
  		printf("%lld\n",ans);
  	}
  }
  return 0;  
}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值