您的位置:首页 > 其它

2015 ACM/ICPC Asia Regional Changchun Online 1012 hdu5448 Marisa’s Cake

2015-09-15 19:30 525 查看
Problem Description

Today is Marisa’s birthday and she is given a cake the shape of a convex polygon of n vertices.
Furthermore, all the n vertices
are all going to be on integer points of the Cartesian coordinate system. Marisa asks her friend Reimu to randomly cut off some vertices of the cake. The set of vertices chosen to be cut off has size at most n−3,
and all possible choices have the same probability to be picked up. In order to remove all chosen vertices, Reimu might cut the cake several times. Since Reimu is a perfectionist, she will always cut the cake from one vertex to another. Hence, Reimu’s cutting
will not generate vertices which are not in the original polygon.

Marisa wants to know the expected size of the cake she might get, and because you are madly in love with her, you decided to do anything she wants for her! You take out your laptop and are ready to calculate the expected size for Marisa. However, Marisa is
bad with fractions. She wants to make sure the answer she gets is always an integer. To do that, she would like you to multiply the answer with the total number of possible cakes there are. Unfortunately, that still doesn’t guarantee the answer be an integer.
An additional 2 must also be multiplied into the answer as well. For example, let A=(0,0),B=(1,0),C=(1,1),D=(0,2) and ABCD is
the shape of Marisa’s birthday cake. There are 5 possible
pieces ABCD,ABC,BCD,CDA,DAB that
Marisa might get, and the corresponding area of these convex polygons are 32,12,12,1,1 respectively.
The expected size of the cake that Marisa might get is (32+12+12+1+1)÷5=910 ,
and what you should tell Marisa 910×5×2=9.
Calculate the answer for Marisa and who knows, maybe she would love you back!

Input

The first line on the input contains an integer T(T≤10).
There will be T test
cases. The first line of each test case contains an integer n(3≤n≤100000)indicating
the number of vertices of the convex polygon. The i−th of
the following n lines
contains two integers xi and yi(0≤x,y≤109) separated
by a blank. (xi,yi) is
the i−th vertex
of the convex polygon, and (x1,y1),...,(xn,yn) will
be in counterclockwise order.

Output

For each test case, output a number as the answer. In case the answer is greater than 1000000006,
please modulo the answer with 1000000007.
(You might figure out by now that Marisa is not good at dealing with large numbers either)

Sample Input

2
4
0 0
1 0
1 1
0 2
5
1 1
3 1
3 2
2 3
1 2


Sample Output

9
50


题意:题意同zoj3871,不过这次给的点集是凸包。

做法:和zoj3871差不多,枚举边,不过由于是一个凸包。所以原来需要n次计算连在一点上的边的有向面积可以预处理然后o(1)计算。

直接看代码就好啦。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define mod 1000000007
#define pi acos(-1.0)
struct Point{
long long x,y;
}p[222111];
int n;
long long er[222222];
int main()
{
int T;
scanf("%d",&T);
er[0]=1;
for(int i=1;i<=200010;i++)
{
er[i]=er[i-1]*2%mod;
}
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%lld%lld",&p[i].x,&p[i].y);
}
long long ans=0;
long long ysum=0,xsum=0,subysum=0,subxsum=0;
for(int i=1;i<n;i++)
{
ysum+=p[i].y*er[n-i-1];
subysum+=p[i].y;
subysum%=mod;
ysum%=mod;
xsum+=p[i].x*er[n-i-1];
subxsum+=p[i].x;
subxsum%=mod;
xsum%=mod;
}
for(int i=0;i<n;i++)
{
ans+=p[i].x*(ysum-subysum)-p[i].y*(xsum-subxsum);
ans%=mod;
ysum-=p[i+1].y*er[n-2];
ysum%=mod;
ysum*=2;
ysum+=p[i].y;
ysum%=mod;
subysum-=p[i+1].y;
subysum+=p[i].y;
subysum%=mod;
xsum-=p[i+1].x*er[n-2];
xsum%=mod;
xsum*=2;
xsum+=p[i].x;
xsum%=mod;
subxsum-=p[i+1].x;
subxsum+=p[i].x;
subxsum%=mod;
}
if(ans<0)ans+=mod;
printf("%lld\n",ans);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: