BZOJ 2321 星器

星器
思路:
势能分析法。
假设每颗星星的势能为\(x^2+y^2\)
那么对于一行的两颗星星\((i, j), (i, k), j < k\)
它转移到\((i, j+1), (i, k-1)\)的势能变化为\(j^2-(j+1)^2+k^2-(k-1)^2=2*(k-j-1)\)
正好是我们魔法值的两倍
代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ll long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

int n, m, a;
LL x, y;
int main() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            scanf("%d", &a);
            x += a*(i*i+j*j);
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            scanf("%d", &a);
            y += a*(i*i+j*j);
        }
    }
    printf("%lld\n", (x-y)/2);
    return 0;
}

posted @ 2019-09-26 20:58  Wisdom+.+  阅读(169)  评论(0编辑  收藏  举报