(Petition training Program) UVa 11054 Wine trading in Gergovia (equivalent conversion)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.