Title Address: UVa 11054
Very ingenious a problem, this problem is the use of equivalent conversion, for each road, if the right production than the left side of the X, then no matter where the starting point is, where the end point, you can take the left and right sides as two points, to transport X Labor from this road. Again because the sum is 0, so only need to calculate the sum of one end can be, so as long as the traversal can be calculated. It's easy to write the code ...
The code is as follows:
#include <iostream> #include <stdio.h> #include <string.h> #include <stdlib.h> #include < math.h> #include <ctype.h> #include <algorithm> #include <queue>using namespace std; #define LL Long Longint Main () { LL n, I, S, X, A; while (scanf ("%lld", &n)!=eof&&n) { s=0; x=0; for (i=0;i<n;i++) { scanf ("%lld", &a); S+=abs (x); x+=a; } printf ("%lld\n", s); } return 0;}
(Petition training Program) UVa 11054 Wine trading in Gergovia (equivalent conversion)