题意:有n个村庄,每个村庄要么买酒(+),要么卖酒(-),要求供需平衡,求最小代价(代价k为把k个单位的酒运到相邻的村庄)。

思路:贪心。可以把第1个村庄的所有酒都从第2个村庄运来,那么12可以合二为一,其他村庄需要运a+b的酒到12村庄,依次类推。

code:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>using namespace std;typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;const int INF=0x3fffffff;
const int inf=-INF;
const int N=1000000;
const int M=2005;
const int mod=1000000007;
const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))
#define cpy(x,a) memcpy(x,a,sizeof(a))
#define fr(i,s,n) for (int i=s;i<=n;i++)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lrt  rt<<1
#define rrt  rt<<1|1
#define middle int m=(r+l)>>1
#define lowbit(x) (x&-x)
#define pii pair<int,int>
#define mk make_pair
#define IN freopen("in.txt","r",stdin);
#define OUT freopen("out.txt","w",stdout);int main()
{int n;while (~scanf("%d",&n),n){ll ans=0,a,la=0;fr(i,1,n){cin>>a;ans+=abs(la);la+=a;}printf("%lld\n",ans);}
}

uva 11054——Wine trading in Gergovia相关推荐

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

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

  2. Uva 11054 - Wine trading in Gergovia(模拟)

    As you may know from the comic "Asterix andthe Chieftain's Shield", Gergovia consists of o ...

  3. UVA 11054 Wine trading in Gergovia

    题意: 一条街上住着连续的n户人家,没相邻的两户人相隔一个单位.街上的每户人都需要买一定数量的葡萄酒或者卖掉葡萄酒,保证所有人家买进的总量与卖出的数量一致.每户可以选择与其他任何家交易.但是因为相隔路 ...

  4. 11054 - Wine trading in Gergovia

    Wine trading in Gergovia As you may know from the comic "Asterix and the Chieftain's Shield&quo ...

  5. POJ2940 HDU1489 UVA11054 Wine Trading in Gergovia【Ad Hoc】

    Wine Trading in Gergovia Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3541   Accepte ...

  6. Wine Trading in Gergovia (贪心)

    As you may know from the comic "Asterix and the Chieftain's Shield", Gergovia consists of ...

  7. uva11054 - Wine trading in Gergovia(等价转换,贪心法)

    这个题看上去麻烦,实际上只要想清楚就很简单.关键是要有一种等价转换的思维方式.其实题意就是个一排数,最后通过相邻的互相移动加减使得所有数都变成零,移动过程中每次都耗费相应值,让耗费的值最小.虽然从实际 ...

  8. UVA 10700 Camel trading

    UVA_10700 我们可以猜到最大值一定是先算和后算积,最小值一定是先算积后算和,因为a*b+c<=a*(b+c). 此外,这个题目数据有可能比较大,所以要采用long long int或者d ...

  9. 紫书《算法竞赛入门经典》

    紫书<算法竞赛入门经典>题目一览 第3章 数组和字符串(例题) UVA 272 TEX Quotes UVA 10082 WERTYU UVA 401 Palindromes UVA 34 ...

最新文章

  1. Easy3D:一个轻量级、易用、高效的C++库,用于处理和渲染3D数据
  2. 树莓派如何卸载mysql_树莓派安装MySQL数据库与卸载
  3. jQuery源码分析系列
  4. springboot配置spring.profiles.active多环境支持
  5. 【NLP技术应用】工业界求解NER问题的12条黄金法则
  6. jsf集成spring_Spring和JSF集成:MVC螺母和螺栓
  7. ThinkPHP6项目基操(13.实战部分 项目中的自定义异常处理总结 错误页面API错误)
  8. Meanshift 均值飘移实现图像聚类 MATLAB实现(4)
  9. 06-R环境中的工作空间(workspace)概念
  10. 机器学习:异常检测算法Seasonal Hybrid ESD及R语言实现
  11. CSS原理与CSS经验分享
  12. TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) ABCD
  13. hibernate查询部分字段加struts2显示
  14. java代码实现压缩文件.gz格式,解压后无后缀名问题
  15. uploadify php demo,php uploadify上传
  16. PLSQL 安装教程
  17. java多线程编程详细入门教程
  18. Effective Java目录
  19. Gym - 100886D 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest D - Catenary
  20. 视频剪辑,轻松将多个视频顺时针旋转90度

热门文章

  1. web前端入门学习(纯干货)
  2. 《SpringMVC从入门到放肆》三、DispatcherServlet的url-pattern配置详解
  3. 使用phpstorm+wamp实现php代码实时调试审计
  4. Spring注入方式及注解配置
  5. 翻译的一篇关于学习编程语言的小文章
  6. shell脚本1——变量 $、read、``
  7. HDU 5691 Sitting in Line 状压dp
  8. 百度云推送的简单集成
  9. Oracle ——如何确定性能差的 SQL
  10. Resharper4.5:增强你的.net开发