bzoj2321 星器
定义一个点的势能是i2+j2,求出两个状态的势能之差。。。
我不会证明。
#include <math.h> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; #define g() getchar() template<class Q>void Scan(Q&x){ char c;int f=1; while(c=g(),c<48||c>57)if(c=='-')f=-1; for(x=0;c>47&&c<58;c=g())x=10*x+c-48; x*=f; } #define fi first #define se second #define mp make_pair #define pb push_back #define inf 0x7f7f7f7f #define Max(x,y) if(x<y)x=y #define Min(x,y) if(x>y)x=y #define rep(i,a,b) for(int i=a;i<b;++i) typedef long long ll; typedef double db; int n,m; ll ans; int main(){ Scan(n),Scan(m); rep(i,1,n+1) rep(j,1,m+1){ int x; Scan(x); ans+=(1ll*i*i+1ll*j*j)*x; } rep(i,1,n+1) rep(j,1,m+1){ int x; Scan(x); ans-=(1ll*i*i+1ll*j*j)*x; } if(ans<0)ans=-ans; printf("%lld\n",ans>>1); return 0; }