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  
#include  
#include  
#include  
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;i5000000)
  	{
  		printf("Too expensive\n");
  	}else{
  		printf("%lld\n",ans);
  	}
  }
  return 0;  
}  

你可能感兴趣的:(R - A Minimum Land Price)