zoj3871Convex Hull

Convex Hull

Time Limit: 3 Seconds       Memory Limit: 65536 KB

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 xiyi which denotes a point (xiyi) (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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值