HDOJ 3420 Bus Fair(动规)

Bus Fair

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


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
 

Author
Muhammed Hedayet
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   3422  3421  3423  3418  3419

题意:我翻了别人的各种帖子才知道题意,比如3  3  7  16,第一个数是有几个人,剩余数是每人坐车要几张票。个人一起坐车下了车的人可以把票给其他的人,只要满足当前的票数够所有人到下一站,就不用买票,否则就需要补足不够的票。问最少满足所有人都到达目的地的票数是多少。第一个人下车时用3张票,即第一,二,三人都用3张票,然后他下车票可以给下一人接着当3张票用,比如给第二人,第二人下车时原本应再用4张票,有了第一人的三张票,他只要再付1张票,第三人付4张票。然后第二人下车,他的所有票,即7张都给第三人,第三人到下车原本要再付9张,可现在只要付2张,一共最少付16张票!           若把最后一个数改为14,即3  3  7  14,最后一个人在第二个人下车后得到7张票就不用再付了,最后结果为14!      若把最后一个数改为13,即3  3  7  13,最后一个人在第二个人下车后得到7张票就不用再付了,并且还多出了一张票没用,最后结果还为14!

一组测试数据:
3  3  7  16   ——16
3  3  7  14   ——14
3  3  7  13   ——14
动态转移方程: cost = max ( cost,(n-i) * a[i] )
#include<cstdio>
#include<algorithm>
#define max(a,b) a>b?a:b
using namespace std;
int main(){
    int a[1005],n,cost,i;
    while(~scanf("%d",&n)){
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        cost=0;
        for(i=0;i<n;i++){
            cost=max(cost,(n-i)*a[i]);
        }
        printf("%d\n",cost);
    }
    return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值