Sicily 1032. Depot

本文介绍了一个涉及多个相互连接油库的平衡问题。每个油库通过管道相连并需要达到油量一致的目标。文章详细阐述了算法流程,包括如何计算平均油量、如何转移油量以达到最小化总转移量的目标。

1032. Depot

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

On the circular road surrounding the city, there are N refueling depots. Every depot has a large warehouse (you may assume the storage capacity is infinite), and is connected with two other depots through oil pipes.

As the circular road is very busy, each depot has to serve such a lot of cars everyday, so the oil is consumed almost the same rapidly at each depot. Usually the depots are respectively supplied by a center warehouse in the city. But recently a war has broken out in Middle East, so the oil supplies are in great shortage, and the center warehouse has no more oil to supply these N depots. But fortunately some of the depots still have a large amount of oil storage. And the oil can be transferred from one depot to another through oil pipes. So, to satisfy the consumption at each depot, the manager of the depots, has decided to rearrange the oil storage, so that each depot contains the same amount of oil.

The oil transfer can be carried out in unlimited times. But for some strange reasons(security, or …, who knows), each time the oil transfer should be carried out in a special way, that is a depot must transfer the same amount of oil to its two neighboring depots. What’s more, the amount of oil transferred should always be in integer units, and of course can not exceed the current storage of the source depot.

Since the oil transfer cost is proportional to the amount of oil transferred, and the manager is not sure whether it’s possible to make such a transfer plan, so that each depot contains the same amount of oil. So now it’s your task to write a program, first answer whether the manager’s goal is possible, and if possible, find a transfer plan so that the total amount of oil transferred is minimized.

Input

       Input may contain several test cases. The first line is a positive integer T(T<=20), denoting the number of test cases followed. Each test case consists of two lines. The first line is a positive integer, N(3<=N<=50000), indicating the number of depots on the circular road. The second line contains N non-negative integers, a1,a2,…an, (ai<=300), denoting the number of units of oil in depot 1, depot 2, …, depot n. For each i satisfying 2<=i<n, depot i is connected with depot i-1 and depot i+1, and depot 1 is also connected with depot n.

Output

For each test case, if it’s impossible to make such a transfer plan, just output “Impossible”(without quotation mark). Otherwise, output an integer in one line, representing the minimum amount of units of oil that should be transferred from one depot to another. No extra blank is allowed.

Sample Input

234 1 131 0 1

Sample Output

2Impossible

Problem Source

ZSUACM Team Member

// Problem#: 1032
// Submission#: 3585062
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>

const int num = 50000;

long long a[num], b[num], c[num], avg, sum, p;
int n;

int main() {
    int i, total;
    scanf("%d", &total);
    while (total--) {
        scanf("%d", &n);
        avg = 0;
        for (i = 0; i < n; i++) {
            scanf("%lld", &a[i]);
            avg += a[i];
        }
        if (avg % n != 0) {
            printf("Impossible\n");
            continue;
        }
        avg /= n;
        sum = 0;
        p = 0;
        for (i = 1; i < n; i++) {
            p += a[i] - avg;
            sum += p;
        }
        if (sum % n != 0) {
            printf("Impossible\n");
            continue;
        }
        c[0] = -sum / n;
        sum = 0;
        b[0] = 0;
        for (i = 1; i < n; i++) {
            c[i] = c[i - 1] + a[i] - avg;
            sum += c[i - 1];
            if (sum > b[0]) b[0] = sum;
        }
        sum = b[0];
        for (i = 1; i < n; i++) {
            b[i] = b[i - 1] - c[i - 1];
            sum += b[i];
        }
        printf("%lld\n", sum * 2);
    }
    return 0;
}                                 


为了查找与测绘遥感相关的SCI期刊列表,可以通过学术搜索引擎或访问特定的数据库来获得最新的信息。通常这些资源会定期更新以反映最新收录情况。 些常用的搜索方式包括: 查阅Web of Science (WOS) 数据库 这是最直接的方法之,因为Science Citation Index(SCI)正是由该数据库维护。可以在其中设置关键词为"remote sensing", "surveying and mapping" 或者更具体的主题术语,并选择仅显示被SCI索引的文章和期刊。 利用Google Scholar 虽然不是专门针对SCI期刊,但可以找到很多高影响力的测绘遥感类文章及其发表刊物的信息。从这里也可以了解到哪些是活跃且受认可的研究领域内的出版物。 参考Journal Citation Reports (JCR) 这是个评估科学和技术期刊影响力的重要工具。通过查看影响因子和其他指标,可以帮助确定哪些测绘遥感领域的期刊最具权威性并且属于SCI范畴。 咨询图书馆员或专业人士 大学或研究机构的专业人员能够提供指导和支持,帮助定位最适合需求的具体期刊名称及详情。 订阅行业通讯和服务 某些服务如Elsevier's Scopus也会报告关于各个学科顶级期刊的消息,保持关注可以获得及时的通知。 以下是几个知名的测绘遥感相关SCI期刊的例子: - Remote Sensing of Environment - IEEE Transactions on Geoscience and Remote Sensing - ISPRS Journal of Photogrammetry and Remote Sensing - International Journal of Applied Earth Observation and Geoinformation 请注意,实际的SCI期刊名单可能会随着时间而变化,因此建议总是使用最新的在线资源来进行确认。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值