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. MySQL修改提示符

    MySQL提示符 \D 完整日期 \d 当前数据库 \h 服务器名称 \u 当前用户 1.连接之前修改提示符 mysql -uroot -proot --prompt [MySQL提示符] 2.连接之 ...

  2. Cookie跳转登录验证码

    对于web应用来说,大部分的系统在用户登录时都要求用户输入验证码,验证码的类型的很多,有字母数字的,有汉字的,甚至还要用户输入一条算术题的答案的, 对于系统来说使用验证码可以有效果的防止采用机器猜测方 ...

  3. mac下 mysql 插入中文乱码解决

    搞了好几个小时,终于搞定了 乱码根本原因还是编码方式不同造成的,只要编码方式统一就没问题 1. 进入 mysql 命令行, 用 show variables like 'character_set_% ...

  4. Spark standalone模式的安装(spark-1.6.1-bin-hadoop2.6.tgz)(master、slave1和slave2)

     前期博客  Spark运行模式概述 Spark standalone简介与运行wordcount(master.slave1和slave2) 开篇要明白 (1)spark-env.sh 是环境变量配 ...

  5. Git使用总结(一):简介与基本操作

    一:简介 GIT是一个开源的分布式的版本控制系统,是由Linus 为了管理Linux内核开发而开发的一个开源的版本控制软件.相比SVN,它采用分布式版本库方式. 二:工作区,暂存区和版本库 左侧为工作 ...

  6. twitter storm常用命令

    1.提交Topologies命令格式:storm jar [jar路径] [拓扑包名.拓扑类名][stormIP地址][storm端口][拓扑名称][参数]eg:storm jar /home/sto ...

  7. 2018年javaee学习目标

    我打算在本学期的学习中把java ee掌握并能熟练应用,如果可以的话还打算编写一个后台服务程序,增加自己的实战经验.

  8. Laravel 使用Voyager导致多个数据库连接总是返回默认连接?

    问题与分析 最近的项目碰到一个奇怪的问题,在Laravel(5.3)中想建立多个数据库连接连到MySQL的不同数据库(另一个连接名为conn2),执行如下语句得到却发现得到的仍然是默认连接: $con ...

  9. Spring 跨域请求

    1.Jsp的跨域请求 后台jsp代码: <%@ page language="java" contentType="text/html; charset=UTF-8 ...

  10. sqlserver 自增ID插入指定数据(转)

    set identity_insert 表名 ON --允许对自增列Id插入指定数据 insert into table_name(Id,Name) values(1,'test') set iden ...