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

 #include<stdio.h>
#include<stdlib.h>
int cmp(const void* a,const void* b)
{
return *(int *)a - *(int *)b;
}
int main()
{
int n,tmp,sum,i;
int num[];
while(~scanf("%d",&n))
{
for(i=;i<n;i++)
scanf("%d",&num[i]);
sum=;
qsort(num,n,sizeof(num[]),cmp);
for(i=;i<n;i++)
{
tmp=num[i]*(n-i);
if(tmp>sum)
sum=tmp;
}
printf("%d\n",sum);
}
return ;
}

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

  1. HDU 3420 Bus Fair [补]

    今天玩魔灵玩多了,耽误了时间,回去宿舍又没电. /*********************************************/ Bus Fair Time Limit: 2000/10 ...

  2. HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛)

    HDU 4046 Panda (ACM ICPC 2011北京赛区网络赛) Panda Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: ...

  3. hdu 5552 Bus Routes

    hdu 5552 Bus Routes 考虑有环的图不方便,可以考虑无环连通图的数量,然后用连通图的数量减去就好了. 无环连通图的个数就是树的个数,又 prufer 序我们知道是 $ n^{n-2} ...

  4. (并查集)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)    Memo ...

  5. hdu 1690 Bus System(Dijkstra最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Bus System Time Limit: 2000/1000 MS (Java/Others ...

  6. 【线段树】HDU 5493 Queue (2015 ACM/ICPC Asia Regional Hefei Online)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5493 题目大意: N个人,每个人有一个唯一的高度h,还有一个排名r,表示它前面或后面比它高的人的个数 ...

  7. hdu 4747 Mex (2013 ACM/ICPC Asia Regional Hangzhou Online)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4747 思路: 比赛打得太菜了,不想写....线段树莽一下 实现代码: #include<iost ...

  8. (二叉树)Elven Postman -- HDU -- 54444(2015 ACM/ICPC Asia Regional Changchun Online)

    http://acm.hdu.edu.cn/showproblem.php?pid=5444 Elven Postman Time Limit: 1500/1000 MS (Java/Others)  ...

  9. (字符串处理)Fang Fang -- hdu -- 5455 (2015 ACM/ICPC Asia Regional Shenyang Online)

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5455 Fang Fang Time Limit: 1500/1000 MS (Java/Others)  ...

随机推荐

  1. input标签的按钮效果

    https://codepen.io/anon/pen/EOPMNy <div class="row"> <p>Click every input.< ...

  2. Request.QueryString 的用法

    比如常见的URL网页地址都有 xxx.asp?type=reLogin   ?号后面的就是querystring querystring是asp中获取数据的一个方法. 那么就可以用request.qu ...

  3. CommandBehavior.CloseConnection有何作用

    其用在ExecuteReader(c)中,返回对象前不能关闭数据库连接,须用CommandBehavior.CloseConnection: 这是一个关于实际知识点的问题,面试官考查的是应聘者数据库访 ...

  4. [目录]hybrid app 开发实战(基于ionic,cordova,angularjs)

    序:为什么要写这个系列 第一章:hybrid app开发之技术选型 第二章:ionic,cordova,phonegap关系浅析 第三章:ionic环境搭建之windows篇 第四章:ionic环境搭 ...

  5. 转:JVM系列三:JVM参数设置、分析

    转自:http://www.cnblogs.com/redcreen/archive/2011/05/04/2037057.html 不管是YGC还是Full GC,GC过程中都会对导致程序运行中中断 ...

  6. Scrum 冲刺博客第一篇

    一.各个成员在 Alpha 阶段认领的任务 成员 Alpha 阶段认领的任务 黄腾龙 主要功能模块代码开发 叶城龙 部分模块代码开发,博客撰写 李心宇 代码测试,博客撰写 余腾鑫 界面设计,博客撰写 ...

  7. HTML <a>标签的使用

    <a></a>标签称作链接标记,由<a>与</a>所围的文字.图片等可以作为一个链接 Eg:<a href="index.html&qu ...

  8. MySQL 8.0 压缩包版安装方法

    转自:https://blog.csdn.net/yangs_2012/article/details/80412016 注意: 操作系统:Windows 10 专业版(64位) MySQL版本:my ...

  9. SQL练习(一)

    查找今天过生日的同学 这里表中已经存储了生日,所以思路是取出date_birth去今天的日期相比较 SELECT NAME,date_birth FROM org_mhi_studentfiles W ...

  10. fzu 2138 久违的月赛之一 容斥。

    Problem 2138 久违的月赛之一 Accept: 40    Submit: 86 Time Limit: 1000 mSec    Memory Limit : 32768 KB Probl ...