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. 【随笔】 MyEclipse2014的安装和破解

    MyEclipse,是在eclipse 基础上加上了自己的插件.MyEclipse,是在eclipse 基础上加上自己的插件开发而成的功能强大的企业级集成开发环境,主要用于Java.Java EE以及 ...

  2. HtmlUnit 开发网络爬虫

    网络爬虫第一个要面临的问题,就是如何抓取网页,抓取其实很容易,没你想的那么复杂,一个开源HtmlUnit包,几行代码就OK啦! 通常在一个页面中会包含别的Url,在别的Url当中又会包含更多的Url. ...

  3. 游戏开发者注意!这个音频SDK可以完美兼容所有主流游戏引擎

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由腾讯游戏云 发表于云+社区专栏 在网络游戏中,无论是大逃杀.棋牌类.电子竞技类还是娱乐休闲类小游戏,玩家和玩家之间的互动.语音聊天是一 ...

  4. android和Linux下getopt的差别

    1. Linux下如果找不到相对应的参数,则会跳过继续找下一个 Android下如果找不到则会直接返回-1,跳出来 2. Linux下通过getopt后会把找到的元素放到数组的前面,没找到的往后移动( ...

  5. Golang教程:goroutine协程

    在上一篇中,我们讨论了并发,以及并发和并行的区别.在这篇教程中我们将讨论在Go中如何通过Go协程实现并发. 什么是协程 Go协程(Goroutine)是与其他函数或方法同时运行的函数或方法.可以认为G ...

  6. ASP.NET MVC4 新手入门教程之一 ---1.介绍ASP.NET MVC4

    你会建造 您将实现一个简单的电影清单应用程序支持创建. 编辑. 搜索和清单数据库中的电影.下面是您将构建的应用程序的两个屏幕截图.它包括显示来自数据库的电影列表的网页: 应用程序还允许您添加. 编辑和 ...

  7. Rabbit主题交换机

    主题交换机类型为:topic. 是直连交换机的一种.只是比直连交换机更灵活,在路由键上引入了通配符的概念 topic交换机支持通配符的路由键. *表示匹配一个词. #匹配所有 生产者 : packag ...

  8. Windows安装配置xampp

    建议大家直接看原文 1.安装XAMPP 进入https://www.apachefriends.org/zh_cn/index.html页面下载XAMPP 2 3.打开xampp控制版 4.修改apa ...

  9. 深入理解ES6之函数

    一:关于函数的参数: 可以接受任意数量的参数而无视函数声明的参数数量是js函数的独特之处. 1:参数默认值 ES6之前做法: function makeRequest(url,timeout,call ...

  10. SASS和LESS等优缺点对比,使用方法总结 (笔记大全)

    sass优点: 用户多,更容易找到会用scss的开发,更容易找到scss的学习资源: 可编程能力比较强,支持函数,列表,对象,判断,循环等: 相比less有更多的功能: Bootstrap/Found ...