hdu 3420 Bus Fair
来源:互联网 发布:linux 父级目录 编辑:程序博客网 时间:2024/06/05 21:04
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.
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
题意 :有 n 个人搭公交车, 问最少买多少公里的票。 票都是1公里的。 下车后票可以给别人,一样可以用。
思路 :每下一个人都因判断, 剩余的人到下一站, 手里应该至有多少票。
遍历一编数组, 取最大的 “至少需要票”, 那就能顺利的,并且买最少的票。
#include<stdio.h>#include<stdlib.h>int cmp(const void *a, const void *b){ return *(int *)a - *(int *)b;}int main() { int x[1001], n, i, j, tickets; while(scanf("%d", &n) != EOF){ for(i = 0; i < n; i++) scanf("%d", x + i); qsort(x, n, sizeof(x[0]), cmp); tickets = 0; for(i = 0; i < n; i++) if(x[i] * (n - i) > tickets) tickets = x[i] * (n - i); printf("%d\n", tickets); }}
- hdu 3420 Bus Fair
- hdu 3420 Bus Fair
- HDU 3420 Bus Fair(贪心)
- hdoj 3420 bus Fair
- HDUOj BUS Fair 题目3420
- HDU:3420 Bus Fair, 3090 Go Home+uva:11729 Commando War(简单贪心)
- HDOJ 3420 Bus Fair(动规)
- HDU3420 Bus Fair
- HDU 1690 Bus System
- HDU 1690 Bus System
- hdu 1690 Bus System
- HDU 1690 Bus System
- HDU 1690 Bus System
- hdu 1690 Bus System
- hdu 1690 Bus System
- hdu 2377Bus Pass
- HDU 2377 Bus Pass
- HDU 1690 Bus System.
- 如何保持积极主动
- openWRT摄像头选购
- 你若安好
- 架设内部yum服务器
- 集成电路的鲁棒性
- hdu 3420 Bus Fair
- Eclipse主要用到的快捷键
- android与html5的交互——数据库操作,UI操作,以及html5的localStorage、定位功能
- 最牛B的 Linux Shell 命令 系列连载
- 调用宿主在Console的WCF报错
- VC中如何调用其他的可执行程序
- python 之 json2
- sql server 2005学习小记
- Linux查看内核、CPU等信息的常用命令