标签:
As Gerald ..., in other words, on a New Year Eve Constantine prepared an unusual present for the Beautiful Lady. The present is the magic New Year snowflake that can make any dream come true.
The New Year snowflake consists of tiny ice crystals, which can be approximately regarded as points on the plane. The beauty of the New Year snowflake is that it has a center of symmetry. This is a point such that for each crystal of the snowflake exists another crystal, symmetrical to it relative to that point. One of the crystals can be placed directly in the center of symmetry.
While Constantine was choosing a snowflake among millions of other snowflakes, no less symmetrical and no less magical, then endured a difficult path through the drifts to the house of his mistress, while he was waiting with bated breath for a few long moments before the Beautiful Lady opens the door, some of the snowflake crystals melted and naturally disappeared. Constantine is sure that there were no more than k of such crystals, because he handled the snowflake very carefully. Now he is ready to demonstrate to the Beautiful Lady all the power of nanotechnology and restore the symmetry of snowflakes.
You are given the coordinates of the surviving snowflake crystals, given in nanometers. Your task is to identify all possible positions of the original center of symmetry.
The first line contains two integers n and k (1 ≤ n ≤ 200 000, 0 ≤ k ≤ 10) — the number of the surviving snowflake crystals and the maximum number of melted crystals, correspondingly. Next n lines contain the coordinates of the crystals that are left in the following form: "xi yi". The coordinates are integers and do not exceed 5·108 in absolute value. All given points are different.
The first line contains an integer c — the number of possible symmetry centers. Next c lines should contain the centers‘ descriptions. Each symmetry center is described by a couple of coordinates "x y", separated by a space. Print the coordinates with absolute error not exceeding 10 - 6. You are allowed to print the symmetry centers in any order. All printed points should be different. If there exist an infinite number of possible symmetry centers, print the single number "-1".
4 0
0 0
0 1
1 0
1 1
1
0.5 0.5
4 2
0 0
0 1
1 0
1 1
5
0.0 0.5
0.5 0.0
0.5 0.5
0.5 1.0
1.0 0.5
4 4
0 0
0 1
1 0
1 1
-1
//参考资料:http://blog.csdn.net/acdreamers/article/details/8521134
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const int N=1e6+5; int d[5005][5005],Am[5005],l[N],A[5005],sum[2],dp[2][5005],n,m,p; void get_table() { d[0][0]=1; for(int i=1;i<=5000;i++) for(int j=1;j<=min(5000,m);j++) d[i][j]=(1LL*d[i-1][j]*(j-1)+d[i-1][j-1])%p; A[0]=Am[0]=1; for(int i=1;i<=min(m,5000);i++) { Am[i]=1LL*Am[i-1]*(m-i+1)%p; A[i]=1LL*A[i-1]*i%p; } } int main() { scanf("%d%d%d",&n,&m,&p); get_table(); for(int i=1;i<=n;i++)scanf("%d",&l[i]); sum[0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=l[i];j++) { dp[1][j]=1LL*Am[j]*d[l[i]][j]%p*sum[0]%p; if(j<=l[i-1]) { dp[1][j]-=1LL*A[j]*dp[0][j]%p*d[l[i]][j]%p; if(dp[1][j]<0)dp[1][j]+=p; } (sum[1]+=dp[1][j])%=p; } memcpy(dp[0],dp[1],4*(l[i]+1)); sum[0]=sum[1]; sum[1]=0; } printf("%d\n",sum[0]); return 0; }
codeforces 140F New Year Snowflake
标签:
原文地址:http://www.cnblogs.com/homura/p/5727254.html