HDU 3420 Bus Fair [补]
今天玩魔灵玩多了,耽误了时间,回去宿舍又没电。
/*********************************************/
Bus Fair
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 900 Accepted Submission(s): 444
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.
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.
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.
1
2
2
2
3
4
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 1234567 int n;
int a[N];
int b[N]; int main()
{
while(~scanf("%d",&n))
{
int ma=;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
for(int i=;i<n;i++)
{
b[i]=a[i]*(n-i);
ma=max(ma,b[i]);
}
cout<<ma<<endl;
}
return ;
}
HDU 3420 Bus Fair [补]的更多相关文章
- HDU 3420 -- Bus Fair ACM
Bus Fair Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- hdu 5552 Bus Routes
hdu 5552 Bus Routes 考虑有环的图不方便,可以考虑无环连通图的数量,然后用连通图的数量减去就好了. 无环连通图的个数就是树的个数,又 prufer 序我们知道是 $ n^{n-2} ...
- hdu 1690 Bus System(Dijkstra最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1690 Bus System Time Limit: 2000/1000 MS (Java/Others ...
- hdu 1690 Bus System (有点恶心)
Problem Description Because of the huge population of China, public transportation is very important ...
- hdu 1690 Bus System (最短路径)
Bus System Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 2377 Bus Pass
Bus Pass Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 1690 Bus System
题目大意:给出若干巴士不同价格的票的乘坐距离范围,现在有N个站点,有M次询问,查询任意两个站点的最小花费 解析:由于是多次查询不同站点的最小花费,所以用弗洛伊德求解 时间复杂度(O^3) 比较基础的弗 ...
- HDU 5552 Bus Routes(NTT+分治)
题意 给定 \(n\) 个点,任意连边,每条边有 \(m\) 种颜色可选,求带环连通图的方案数. \(1\leq n\leq 10000\) \(1\leq m < 2^{31}\) 思路 直接 ...
- HDU 4696 Answers (脑补+数形结合)
题意 给一个图,每个点的出度为1,每个点的权值为1或者2.给Q个询问,问是否能找到一条路径的权值和M. 思路 由于每个点的出度为1,所以必然存在环.又因为c[i]只能取1或者2,可以组成任意值,所以只 ...
随机推荐
- luogu3629 [APIO2010]巡逻
创造一个环出来,可以让环上的边都只访问一次. 对于 \(k=1\),答案就是树的直径两边连起来. 倘若 \(k=2\),那就先按照 \(k=1\) 的求一遍,然后我们发现,如果第二条加的边构成的环和第 ...
- HDU 5016 Mart Master II
Mart Master II Time Limit: 6000ms Memory Limit: 65536KB This problem will be judged on HDU. Original ...
- MySQL binlog_rows_query_log_events在线设置无效
binlog_rows_query_log_events 对binlog_format=row有效,设为true后可以在binary log中记录原始的语句 官方文档显示binlog_rows_que ...
- Mysql 主外键与索引之间的区别和联系
系数据库依赖于主键,它是数据库物理模式的基石.主键在物理层面上只有两个用途: 惟一地标识一行. 作为一个可以被外键有效引用的对象. 索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一个组成部 ...
- Spark与Pandas中DataFrame对比(详细)
Pandas Spark 工作方式 单机single machine tool,没有并行机制parallelism不支持Hadoop,处理大量数据有瓶颈 分布式并行计算框架,内建并行机制paral ...
- BZOJ 2300 [HAOI2011]防线修建 ——计算几何
只需要倒着插入,然后维护一个凸包就可以了. 可以用来学习set的用法 #include <map> #include <set> #include <cmath> ...
- BZOJ 2179 FFT快速傅立叶 ——FFT
[题目分析] 快速傅里叶变换用于高精度乘法. 其实本质就是循环卷积的计算,也就是多项式的乘法. 两次蝴蝶变换. 二进制取反化递归为迭代. 单位根的巧妙取值,是的复杂度成为了nlogn 范德蒙矩阵计算逆 ...
- BZOJ 3569 DZY Loves Chinese II ——线性基
[题目分析] 腊鸡题目卡题面. 大概的意思就是给一张无向图,每次删掉其中一些边,问是否联通. 首先想到的是Bitset,可以做到n^2/64.显然过不了. 然而这是lyd在给我们讲线性基的时候的一道题 ...
- P1279 字串距离 (动态规划)
题目描述 设有字符串X,我们称在X的头尾及中间插入任意多个空格后构成的新字符串为X的扩展串,如字符串X为”abcbcd”,则字符串“abcb□cd”,“□a□bcbcd□”和“abcb□cd□”都是X ...
- 纯干货,Mysql innodb的ACID特性是怎么实现的?以及高并发情况下会出现的问题
首先说说什么是ACID: 它们分别是Atomicity(原子性),Consistency(一致性),Isolation(隔离性),Transaction(持久性) 原子性: 意为单个事务里的多个操作要 ...