【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

考虑第一个店。
如果它要酒的话,只能从第二个店那里运过来。
这样,问题就转化成后n-1个店的问题了。
然后会发现,第二家店它的情况也是同样的。
即a[2] = a[1]+a[2];
然后做相同的事情。a[2]的需求量只能从第3家店运过来(送过去)。
每一段路的花费就是∑ai的绝对值。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
一定在这里写完思路再敲代码!!!
*/
#include <bits/stdc++.h>
#define ll long long
using namespace std; int n; int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
while (cin >> n && n){
ll now = 0,ans = 0;
for (int i = 1;i <= n;i++){
int x;
cin >> x;
ans += abs(now);
now+=x;
}
cout << ans << endl;
}
return 0;
}

最新文章

  1. 表格与ckeckbox的全选与单选
  2. C# socket UDPの异步链接
  3. Redis有序集合Zset(sorted set)
  4. net.ipv4.tcp_tw_recycle
  5. C#获取QQ旋风的下载记录
  6. Redis基本数据类型
  7. POJ2942 Knights of the Round Table 点双连通分量,逆图,奇圈
  8. SQL Server 全文索引的管理
  9. Alice and Bob HDU - 4111 (SG函数)
  10. c/c++ 多线程 unique_lock的使用
  11. Linux - ansible 安装
  12. jQuery源码分析学习--资料收集--更新中
  13. 机器学习随笔01 - k近邻算法
  14. 分布式计算(三)Azkaban介绍
  15. 峰Redis学习(6)Redis 数据结构(sorted-set的操作)
  16. HDU 6118 度度熊的交易计划(最小费用最大流)
  17. 关于sentinel LDK加密war包实现应用加密的使用方法
  18. Log Parser 2.2 + Log Parser Lizard GUI 分析IIS日志示例
  19. MySQL 的IFNULL()、ISNULL()和NULLIF()函数
  20. 【HDU5730】Shell Necklace(多项式运算,分治FFT)

热门文章

  1. ddr sdram self-refresh &amp; auto-refresh
  2. html 笔记2
  3. IOC DI 专题
  4. Windows10上使用windbg调试Chromium Windows。
  5. Python正则表达式初识(二)
  6. Copying GC (Part one)
  7. OpenJDK源码研究笔记(十二):JDBC中的元数据,数据库元数据(DatabaseMetaData),参数元数据(ParameterMetaData),结果集元数据(ResultSetMetaDa
  8. [Javascript] this in Function Calls
  9. 【Android界面实现】使用GestureOverlayView控件实现手势识别
  10. ASP.Net MVC默认目录结构