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的更多相关文章

  1. UVA 11054 Wine trading in Gergovia 葡萄酒交易 贪心+模拟

    题意:一题街道上很多酒店,交易葡萄酒,正数为卖出葡萄酒,负数为需要葡萄酒,总需求量和总售出量是相等的,从一家店到另外一家店需要路费(路费=距离×运算量),假设每家店线性排列且相邻两店之间距离都是1,求 ...

  2. UVa 11054 Wine trading in Gergovia【贪心】

    题意:给出n个等距离的村庄,每个村庄要么买酒,要么卖酒,买酒和卖酒的总量相等, 把k个单位的酒从一个村庄运送到相邻的村庄,需要耗费k个单位劳动力,问怎样运送酒使得耗费的劳动力最少 买     卖    ...

  3. UVa 11054 Wine trading in Gergovia

    题意: 直线上有n个等距的酒庄,每个酒庄对酒的需求量为ai(正数说明需要买酒,负数需要卖酒),而且保证所有的酒庄供需平衡. 搬运x个单位的酒到相邻的酒庄需要x个劳动力,求要使所有酒庄供需平衡最少需要多 ...

  4. UVA 11054 Wine trading in Gergovia(思维)

    题目链接: https://vjudge.net/problem/UVA-11054 /* 问题 输入村庄的个数n(2=<n<=100000)和n个村庄的数值,正代表买酒,负代表卖酒,k个 ...

  5. UVA - 11054 Wine trading in Gergovia 扫描法

    题目:点击打开题目链接 思路:考虑第一个村庄,如果第一个村庄需要买酒,那么a1>0,那么一定有劳动力从第二个村庄向第一个村庄搬酒,这些酒可能是第二个村庄生产的,也可能是从其他村庄搬过来的,但这一 ...

  6. UVA - 11054 Wine trading in Gergovia (Gergovia 的酒交易)(贪心+模拟)

    题意:直线上有n(2<=n<=100000)个等距的村庄,每个村庄要么买酒,要么卖酒.设第i个村庄对酒的需求为ai(-1000<=ai<=1000),其中ai>0表示买酒 ...

  7. 【例题 8-5 UVA - 11054】Wine trading in Gergovia

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 考虑第一个店. 如果它要酒的话,只能从第二个店那里运过来. 这样,问题就转化成后n-1个店的问题了. 然后会发现,第二家店它的情况也 ...

  8. 【uva 11054】Wine trading in Gergovia(算法效率--等价转换)

    题意:N个等距村庄,买(>0)卖(<0)酒,供需平衡,运K则需K劳动力.问所需的最小劳动力. 解法:由于运出或运入1的都需经过2,所以无论如何,都可以等价于从2本身运入或运出.因此可以将1 ...

  9. 8-5 Wine trading in Gergovia Gergovia的酒交易 uva11054

    等价转换思维题 题意: 直线上有n(2<=n<=100000)个等距的村庄  每个村庄要么买酒 要么卖酒  设第i个村庄对酒的需求量为ai  绝对值小于一千  其中ai大于0表示买酒   ...

随机推荐

  1. 开源的javascript实现页面打印功能,兼容所有的浏览器(情况属实)

    这篇文章完全是属于技术文章,也是记录一下自己在项目当中遇到的坑爹问题啊,因为是B/S的程序,所以打印功能还是必须要有的,对于打印我选择了一个js插件,发现非常的简单和方便,所以这里拿出来和大家分享一下 ...

  2. tomcat+webservice实现简单的web服务远程调用接口

    1,准备工作:    ①需要使用到jaxws的一系列架包,网址:http://jax-ws.java.net,我下的是比较新的一个版本(下载好以后吧架包发在lib下),②webservice的一个工具 ...

  3. 回文串---Best Reward

    HDU   3613 Description After an uphill battle, General Li won a great victory. Now the head of state ...

  4. PhpStorm的open in browser怎么修改端口和相对路径

    昨天下班后,在电脑安装phpstorm.xampp安装正常,但是在phpstorm上直接打开网站文件一直报错,一直报错502.我感觉好奇快,怎么会报错呢.后面我用hbuild打开文件,在浏览器显示正常 ...

  5. .NET Core的“dotnet restore”、“dotnet build”和“dotnet run”命令都是用来干什么的?

    dotnet restore 源代码:https://github.com/dotnet/cli/tree/rel/1.0.0/src/dotnet/commands/dotnet-restore 入 ...

  6. C#内存占用大量资源的解决办法

    昨天,独立完成了一个项目,一直运行起,起初运行内存为15Mb左右,但是发现内存以每秒2Mb的速度增加,吓了我一跳(注:我实习生,我的工作中第一个项目).从头找寻对象,再来dispose,弄得我晕头转向 ...

  7. vector,arraylist, linkedlist的区别是什么

    LinkedList类 LinkedList实现了List接口,允许null元素. 此外LinkedList提供额外的get,remove,insert方法在LinkedList的首部或尾部. Lin ...

  8. IOS开发支付宝集成

    开发准备 1.首先新建项目,然后去官网下载最新的开发包:http://doc.open.alipay.com/doc2/detail?treeId=59&articleId=103563&am ...

  9. PAT 01-1

    #include <stdio.h> int main() { int i; int k; ]; scanf("%d", &k); ; i < k; i+ ...

  10. 我的mac上的软件(以防优盘重装系统使用)