hdu5448(三角剖分+前缀和)

题意:按逆时针给定一个凸多边形上的点,选取若干个点形成凸包,这些所有凸包的面积之和的2倍

这个题以前就碰过,印象深刻(指标题),然后刚好看见tls写了这题的题解就瞄了一眼。。

其实。。就只是一个结论而已,一个三角剖分的应用。。

令原点和凸包的顶点(逆时针排列)构成的向量分别为f_1,f_2...f_k

那么利用三角剖分该凸包的面积可以表示为\sum_{i=1}^{k-1}f_i\times f_{i+1}+f_k\times f_1

然后就直接考虑f_i\times f_j的贡献就可以了,演着i->j这个方向至少要有一个点和他构成凸包,所以有

\sum_{i=1}^{n}\sum_{j=i+1}^{n}(f_i\times f_j(2^{n-(j-i-1)}-1)+f_j\times f_i(2^{j-i+1}-1))\\= 2^{n-1}\sum_{i=1}^n2^if_i\times\sum_{j=i+1}^n 2^{-j}f_j-\frac{1}{2}\sum_{i=1}^n2^{-i}f_i\times\sum_{j=i+1}^n2^jf_j

然后求个前缀和就能降成O(n)

 

 

 

/**
 *          ┏┓    ┏┓
 *          ┏┛┗━━━━━━━┛┗━━━┓
 *          ┃       ┃  
 *          ┃   ━    ┃
 *          ┃ >   < ┃
 *          ┃       ┃
 *          ┃... ⌒ ...  ┃
 *          ┃              ┃
 *          ┗━┓          ┏━┛
 *          ┃          ┃ Code is far away from bug with the animal protecting          
 *          ┃          ┃   神兽保佑,代码无bug
 *          ┃          ┃           
 *          ┃          ┃        
 *          ┃          ┃
 *          ┃          ┃           
 *          ┃          ┗━━━┓
 *          ┃              ┣┓
 *          ┃              ┏┛
 *          ┗┓┓┏━━━━━━━━┳┓┏┛
 *           ┃┫┫       ┃┫┫
 *           ┗┻┛       ┗┻┛
 */ 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<set>
#include<bitset>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 100005
#define nm 1025
#define pi 3.1415926535897931
const ll inf=1e9+7;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}
 
 



struct P{
    ll x,y;
    P operator*(const ll&o){return P{x*o%inf,y*o%inf};}
    ll operator*(const P&o){return (x*o.y%inf-y*o.x%inf+inf)%inf;}
    void operator+=(const P&o){(x+=o.x)%=inf;(y+=o.y)%=inf;}
}a[NM],b[NM],c[NM];
int n;
ll inv2,p[NM],invp[NM],ans;


int main(){
    n=100000;inv2=inf+1>>1;
    p[0]=1;invp[0]=1;
    inc(i,1,n)p[i]=(p[i-1]<<1)%inf,invp[i]=invp[i-1]*inv2%inf;
    int _=read();while(_--){
	ans=0;
	n=read();inc(i,1,n)a[i].x=read(),a[i].y=read();
	inc(i,1,n)b[i]=a[i]*p[i],c[i]=a[i]*invp[i];
	dec(i,n-1,1){
	    ans+=b[i]*c[i+1]*p[n]%inf-c[i]*b[i+1];ans%=inf;
	    b[i]+=b[i+1];c[i]+=c[i+1];
	}
	if(ans<0)ans+=inf;
	ans*=inv2;ans%=inf;
	printf("%lld\n",ans);
    }
    return 0;
}

 

 

 

 

Marisa’s Cake

Time Limit: 3000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 340    Accepted Submission(s): 198


 

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 ith of the following n lines contains two integers xi and yi(0≤x,y≤109) separated by a blank. (xi,yi) is the ith 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

 

 

Source

2015 ACM/ICPC Asia Regional Changchun Online

 

 

Recommend

hujie   |   We have carefully selected several similar problems for you:  6460 6459 6458 6457 6456 

 

 

Statistic | Submit | Discuss | Note

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值