HDU 3420 -- Bus Fair ACM

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

2
1
2
2
2
3

Sample Output

2
4

题目链接: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 }

HDU 3420 -- Bus Fair ACM

时间: 2024-10-21 00:29:50

HDU 3420 -- Bus Fair ACM的相关文章

hdu 1690 Bus System(Floyd)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Problem Description Because of the huge population of China, public transportation is very important. Bus is an important transportation method in traditional public transportation system. And it's

hdu 1690 Bus System(Dijkstra最短路)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6569    Accepted Submission(s): 1692 Problem Description Because of the huge popula

hdu 1690 Bus System (最短路径)

Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6082    Accepted Submission(s): 1560 Problem Description Because of the huge population of China, public transportation is very importa

hdu 1960 Bus System

Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6166    Accepted Submission(s): 1580 Problem Description Because of the huge population of China, public transportation is very importa

hdu 2377 Bus Pass

Bus Pass Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 667    Accepted Submission(s): 271 Problem Description You travel a lot by bus and the costs of all the seperate tickets are starting to

hdu 1690 Bus System(最短路)

问题: 链接:点击打开链接 题意: 思路: 代码: #include <iostream> #include <cstdio> #include <cstring> using namespace std; #define INF 1000000000000 typedef __int64 LL; const int N = 110; __int64 dis[N][N],place[N]; __int64 L1,L2,L3,L4,C1,C2,C3,C4; int n,m

hdu 5552 Bus Routes

hdu 5552 Bus Routes 考虑有环的图不方便,可以考虑无环连通图的数量,然后用连通图的数量减去就好了. 无环连通图的个数就是树的个数,又 prufer 序我们知道是 $ n^{n-2} $ 其中又由于有 $ n-1 $ 个边,每个边可以涂色,所以总共无环的方案数量是 $ m^{n-1} n^{n-2} $ 那么现在就要算连通图的数量了.这个不如不连通图的数量好算. 不连通图的数量怎么算呢,原本想的是容斥,但是貌似不好实现,看了题解发现一种神仙思路.考虑固定一个点,并且让这个点连出一

HDUOj BUS Fair 题目3420

 简单题  只需检验每次下车钱数够不够即可  不够更新sum #include<stdio.h> #include<stdlib.h> #define N 1005 int a[N]; int cmp(const void *a,const void *b) {return *(int *)a-*(int *)b;} int main() { int n; while(~scanf("%d",&n)) { int sum=0; for(int i=0

(并查集)Travel -- hdu -- 5441(2015 ACM/ICPC Asia Regional Changchun Online )

http://acm.hdu.edu.cn/showproblem.php?pid=5441 Travel Time Limit: 1500/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2061    Accepted Submission(s): 711 Problem Description Jack likes to travel around the wo