题目描述:
给定平面上n个点的坐标,并且我们定义两个点的距离为曼哈顿距离.
曼哈顿距离是指对两个点(x1,y1),(x2,y2)他们之间的距离为∣x2−x1∣+∣y2−y1∣众所周知三个点可以构成一个三角形,那么nnn个点可以构成Cn3个三角形,现在你需要求出所有三角形的周长和 输出在模9982443539意义下的答案.数据保证不存在三点共线.
输入描述:
第一行一个整数表示n.
接下来n行每行两个整数x,y表示一个点.
输出描述:
输出一个整数表示周长和.
输入:
3
0 0
1 0
1 1
输出:
4
题意:
题目描述
题解:
由于不存在三点一线
枚举两个点,剩下n-2个点
那么对于任意两个点,都可以与其他n-2个点形成三角形
也就是这两个点的边出现在了n-2个三角形中
也就是n-2次
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int maxn = 1000 + 5;
const int mod = 998244353;
typedef long long ll;
struct point{
ll x,y;
};
point a[maxn];
ll cal(ll x1,ll y1,ll x2,ll y2){
return abs(x1 - x2) + abs(y1 - y2);
}
int main(){
int n;
while(scanf("%d",&n)!=EOF){
ll ans = 0;
for(int i = 0; i < n; i ++){
scanf("%lld%lld",&a[i].x,&a[i].y);
}
for(int i = 0; i < n; i ++){
for(int j = i + 1; j < n; j ++){
ans += (n - 2) * cal(a[i].x,a[i].y,a[j].x,a[j].y);
ans %= mod;
}
}
printf("%lld\n",ans);
}
return 0;
}