HDU 3420 -- Bus Fair ACM

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   java   os   io   

Bus Fair

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 600    Accepted Submission(s): 293

 

Problem Description

 

You are now in Foolish Land. Once moving in Foolish Land you found that there is a strange Bus fair system. The fair of moving one kilometer by bus in that country is one coin. If you want to go to X km and your friend wants to go to Y km then you can buy a ticket of X+Y coins (you are also allowed to buy two or more tickets for you two).    Now as a programmer, you want to show your creativity in buying tickets! Suppose, your friend wants to go 1 km and you want to go 2 km. Then it’s enough for you to buy a 2coin ticket! Because both of you are valid passengers before crossing the first km. and when your bus cross the first km your friend gets down from the bus. So you have the ticket of 2km! And you can safely reach to your destination, 2km using that ticket.    Now, you have a large group of friends and they want to reach to different distance. You think that you are smart enough that you can buy tickets that should manage all to reach their destination spending the minimum amount of coins. Then tell us how much we should at least pay to reach our destination.

 

Input

 

There are multiple test cases. Each case start with a integer n, the total number of people in that group. 0<=n<=1000. Then comes n integers, each of them stands for a distance one of the men of the group wants to go to. You can assume that the distance a man wants to go is always less than 10000.

 

Output

 

Your program should print a single integer for a single case, the minimum amount of coins the group should spend to reach to the destination of all the members of that group.

 

Sample Input

 

212223

 

Sample Output

 

24

題目連結:http://acm.hdu.edu.cn/showproblem.php?pid=3420
 1 #include<stdio.h> 2 #include<stdlib.h> 3 int cmp(const void* a,const void* b) 4 { 5     return *(int *)a - *(int *)b; 6 } 7 int main() 8 { 9     int n,tmp,sum,i;10     int num[10000];11     while(~scanf("%d",&n))12     {13         for(i=0;i<n;i++)14             scanf("%d",&num[i]);15         sum=0;16         qsort(num,n,sizeof(num[0]),cmp);17         for(i=0;i<n;i++)18         {19             tmp=num[i]*(n-i);20             if(tmp>sum)21                 sum=tmp;22         }23         printf("%d\n",sum);24     }25     return 0;26 }


 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.