Edward has n points on the plane. He picks a subset of points (at least three points), and defines the beauty of the subset as twice the area of corresponding convex hull. Edward wants to know summation of the beauty of all possible subsets of points (at least three points).
No two points coincide and no three points are on the same line.
Input
There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:
The first line contains an integer n (3 ≤ n ≤ 1000). Each of following n lines contains 2 integers xi, yi which denotes a point (xi, yi) (0 ≤ |xi|, |yi| ≤ 109).
The sum of values n for all the test cases does not exceed 5000.
Output
For each case, if the answer is S, output a single integer denotes S modulo 998244353.
Sample Input
1 3 0 0 0 1 1 0
Sample Output
1
考虑每一条边作为凸包中的边出现的次数算出利用叉积算出该边对所构成凸包的面积的贡献值即可
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<list>
#define PI acos(-1.0)
#define MOD 998244353
using namespace std;
const int maxn=1010;
struct point{
int x,y;
double ang;
};
point p[maxn],temp[maxn<<1];
bool cmp(point a,point b){
return a.ang<b.ang;
}
int pow2[maxn];
void init(){
pow2[0]=1;
for(int i=1;i<maxn;++i){
pow2[i]=pow2[i-1]*2%MOD;
}
}
int area(point a,point b){
return (((long long)a.x*b.y%MOD-(long long)a.y*b.x%MOD)%MOD+MOD)%MOD;
}
int main()
{
init();
int t,i,j,k,n;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(i=0;i<n;++i){
scanf("%d%d",&p[i].x,&p[i].y);
}
int ans=0;
for(i=0;i<n;++i){//将i点设为坐标原点
int cnt=0;
for(j=0;j<n;++j){//算出该点与i点与x轴的夹角
if(i==j)continue;
temp[cnt]=p[j];
temp[cnt++].ang=atan2(p[j].y-p[i].y,p[j].x-p[i].x);
}
for(j=0;j<n;++j){
temp[j+cnt]=temp[j];//因为atan2的返回值为-PI到PI所以通过+2PI可以将负角化为正角
temp[j+cnt].ang+=2.0*PI;
}
sort(temp,temp+2*cnt,cmp);
int r=0;
for(int l=0;l<cnt;++l){
while(temp[r+1].ang-temp[l].ang<PI)r++;//计算出在已点i和点l形成的边的一侧有多少个点即该边作为凸包中的边出现的次数从这些点中选出C[x][1]+C[x][2]+...+C[x][x]=2(x)-1;
ans=(ans+(long long)area(p[i],temp[l])*((pow2[r-l]-1+MOD)%MOD)%MOD)%MOD;//因为求得是面积的2倍因此无需再除2
}
}
printf("%d\n",ans);
}
return 0;
}