hdoj 3420 bus Fair
来源:互联网 发布:winhex数据恢复步骤 编辑:程序博客网 时间:2024/05/17 08:48
Bus Fair
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 897 Accepted Submission(s): 442
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.
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
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int x[1001],n,i,j,max;
while(~scanf("%d",&n))
{
for(i=0;i<n;++i)
scanf("%d",x+i);
qsort(x,n,sizeof(x[0]),cmp);
max=0;
for(i=0;i<n;++i)
if(x[i]*(n-i)>max)
max=x[i]*(n-i);
printf("%d\n",max);
}
return 0;
}
0 0
- hdoj 3420 bus Fair
- HDOJ 3420 Bus Fair(动规)
- hdu 3420 Bus Fair
- hdu 3420 Bus Fair
- HDUOj BUS Fair 题目3420
- HDU 3420 Bus Fair(贪心)
- HDU3420 Bus Fair
- HDU:3420 Bus Fair, 3090 Go Home+uva:11729 Commando War(简单贪心)
- hdoj 1690 Bus System
- 【BestCoder】 HDOJ 5163 Taking Bus
- HDOJ 2377 / ZOJ 2913 Bus Pass
- hdoj 1690 Bus System 【最短路径】
- HDOJ 2377 Bus Pass(建图 + BFS)
- Codeforces Round #436 (Div. 2) A.Fair Game B.Polycarp and Letters C. Bus D.Make a Permutation!
- bus
- BUS
- bus
- HDOJ 题目1690Bus System(最短路径)
- 简述逻辑操作(&,|,^)与条件操作(&&,||)的区别
- 1.2-对象的建立-main
- 为什么Docker没有在生产环境取得广泛成功
- Using namespace 命令空间(二)
- 1.2-对象的建立-m
- hdoj 3420 bus Fair
- 1.2-对象的建立-h
- 嵌入式linux工程师面试题目C语言基础部分(问答题)
- Spring讲解------------SSH开发积分商城
- UI_UIView
- NGUI scrollview 笔记
- 课堂笔记06
- 教你快速高效接入SDK——Unity统一接入渠道SDK(Android篇)
- Google Protocol Buffer 的使用和原理