该题目和大吉大利有相同的思路。
我一直都在想三角形怎么求和,怎么统计。
直到比赛结束后,看了看别人的代码醍醐灌顶,因为每一个边都需要C(n-2,2)次出现,所以答案就是每一条边乘以对应的数量即可。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const int N = 1e3+10;
const int M = 40 ;
ll x[N],y[N];
ll dis[N][N];
ll sum[N][N] ;
int main()
{
int n ;
ll ans = 0 ;
scanf("%d",&n);
for( int i = 1 ; i <= n ; i++ ){
scanf("%lld%lld",&x[i],&y[i]);
}
for( int i = 1 ; i <= n ; i++ ){
for( int j = i + 1 ; j <= n ; j ++ ){
dis[i][j] = abs(x[i]-x[j]) + abs(y[i]-y[j]);
ans = ( ans + (n-2) * dis[i][j] % mod ) % mod ;
}
}
printf("%lld\n",ans);
return 0;
}
京公网安备 11010502036488号