uva 11054 wine trading in gergovia (归纳【好吧这是我自己起的名字】)——yhx
As you may know from the comic \Asterix and the Chieftain's Shield", Gergovia consists of one street,
and every inhabitant of the city is a wine salesman. You wonder how this economy works? Simple
enough: everyone buys wine from other inhabitants of the city. Every day each inhabitant decides how
much wine he wants to buy or sell. Interestingly, demand and supply is always the same, so that each
inhabitant gets what he wants.
There is one problem, however: Transporting wine from one house to another results in work. Since
all wines are equally good, the inhabitants of Gergovia don't care which persons they are doing trade
with, they are only interested in selling or buying a specic amount of wine. They are clever enough
to gure out a way of trading so that the overall amount of work needed for transports is minimized.
In this problem you are asked to reconstruct the trading during one day in Gergovia. For simplicity
we will assume that the houses are built along a straight line with equal distance between adjacent
houses. Transporting one bottle of wine from one house to an adjacent house results in one unit of
work.
Input
The input consists of several test cases. Each test case starts with the number of inhabitants n
(2 n 100000). The following line contains n integers ai (
uva 11054 wine trading in gergovia (归纳【好吧这是我自己起的名字】)——yhx的更多相关文章
- UVA 11054 Wine trading in Gergovia 葡萄酒交易 贪心+模拟
题意:一题街道上很多酒店,交易葡萄酒,正数为卖出葡萄酒,负数为需要葡萄酒,总需求量和总售出量是相等的,从一家店到另外一家店需要路费(路费=距离×运算量),假设每家店线性排列且相邻两店之间距离都是1,求 ...
- UVa 11054 Wine trading in Gergovia【贪心】
题意:给出n个等距离的村庄,每个村庄要么买酒,要么卖酒,买酒和卖酒的总量相等, 把k个单位的酒从一个村庄运送到相邻的村庄,需要耗费k个单位劳动力,问怎样运送酒使得耗费的劳动力最少 买 卖 ...
- UVa 11054 Wine trading in Gergovia
题意: 直线上有n个等距的酒庄,每个酒庄对酒的需求量为ai(正数说明需要买酒,负数需要卖酒),而且保证所有的酒庄供需平衡. 搬运x个单位的酒到相邻的酒庄需要x个劳动力,求要使所有酒庄供需平衡最少需要多 ...
- UVA 11054 Wine trading in Gergovia(思维)
题目链接: https://vjudge.net/problem/UVA-11054 /* 问题 输入村庄的个数n(2=<n<=100000)和n个村庄的数值,正代表买酒,负代表卖酒,k个 ...
- UVA - 11054 Wine trading in Gergovia 扫描法
题目:点击打开题目链接 思路:考虑第一个村庄,如果第一个村庄需要买酒,那么a1>0,那么一定有劳动力从第二个村庄向第一个村庄搬酒,这些酒可能是第二个村庄生产的,也可能是从其他村庄搬过来的,但这一 ...
- UVA - 11054 Wine trading in Gergovia (Gergovia 的酒交易)(贪心+模拟)
题意:直线上有n(2<=n<=100000)个等距的村庄,每个村庄要么买酒,要么卖酒.设第i个村庄对酒的需求为ai(-1000<=ai<=1000),其中ai>0表示买酒 ...
- 【例题 8-5 UVA - 11054】Wine trading in Gergovia
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑第一个店. 如果它要酒的话,只能从第二个店那里运过来. 这样,问题就转化成后n-1个店的问题了. 然后会发现,第二家店它的情况也 ...
- 【uva 11054】Wine trading in Gergovia(算法效率--等价转换)
题意:N个等距村庄,买(>0)卖(<0)酒,供需平衡,运K则需K劳动力.问所需的最小劳动力. 解法:由于运出或运入1的都需经过2,所以无论如何,都可以等价于从2本身运入或运出.因此可以将1 ...
- 8-5 Wine trading in Gergovia Gergovia的酒交易 uva11054
等价转换思维题 题意: 直线上有n(2<=n<=100000)个等距的村庄 每个村庄要么买酒 要么卖酒 设第i个村庄对酒的需求量为ai 绝对值小于一千 其中ai大于0表示买酒 ...
随机推荐
- 【JS复习笔记】01 基本语法
数字: JS只有一种数字类型,相当于double.(不知道为什么,我每次打double输入法都会出现逗比了三个字) NaN是一个数值,可以用isNaN(number)检测NaN Infinity表示所 ...
- MySQL联接操作
在MySQL中,联接是一种对表的引用, 多表联接类型: 1.笛卡尔积(交叉联接):在MySQL中为CROSS JOIN或省略JOIN,如: select * from course, teachcou ...
- python之import机制
1. 标准 import Python 中所有加载到内存的模块都放在 sys.modules .当 import 一个模块时首先会在这个列表中查找是否已经加载了此模块,如果加载了则只是将 ...
- 二、SQL语句映射文件(2)增删改查、参数、缓存
//备注:该博客引自:http://limingnihao.iteye.com/blog/106076 2.2 select 一个select 元素非常简单.例如: Xml代码 收藏代码 <!- ...
- ahjesus 获取当前方法被调用执行的具体位置,包括命名空间和方法
MethodBase method = ).GetMethod(); string ahjesus = method.ReflectedType.FullName + "." + ...
- httpclient 认证方式访问http api/resutful api并获取json结果
最近,因公司线上环境rabbitmq经常发生堆积严重的现象,于是跟运维组讨论,帮助开发个集中监控所有rabbitmq服务器运行情况的应用,需要通过java访问rabbitmq暴露的http api并接 ...
- andriod RadioButton
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout android:orientatio ...
- Android根据APP包名启动应用
public void openApp(String packageName, Context context) { PackageManager packageManager = context.g ...
- 生命游戏/Game of Life的Java实现(转)
首先简单介绍一下<生命游戏> 生命游戏其实是一个零玩家游戏.它包括一个二维矩形世界,这个世界中的每个方格居住着一个活着的或死了的细胞.一个细胞在下一个时刻生死取决于相邻八个方格中活着的或死 ...
- C# 图片处理(压缩、剪裁,转换,优化)
1.图片与二进制的转换 图片转换成二进制主要用于数据库存储及图片数据的应用间传输,如网站服务器通过WebService或WCF从数据处理服务器获取图片数据,就可以以二进制形式传输 ///图片转二进制 ...