uva 11054

it2022-05-23  62

据说这叫扫描法,,,,感觉就是脑洞啊,,,,,反正从最左端开始,如果有酒就往后运,需要酒就运负的,就是相当于后面有酒了就运回来。。。

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll; int n; int main() { while(~scanf("%d",&n)&&n) { ll ans=0,last=0; for(int i=0;i<n;i++) { int a; scanf("%d",&a); last+=a; ans+=abs(last); } printf("%lld\n",ans); } return 0; }

 

转载于:https://www.cnblogs.com/Wangwanxiang/p/6838287.html


最新回复(0)