您的位置:首页 > 其它

poj 1809 Regetni——组合数学

2011-09-15 22:31 330 查看
A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2
Try to make clever use of this formula.

先开始怎么想都没有头绪,后来瞄了一眼discuss,有人说其实每个点的坐标只对2的模数有意义。。就有点思路了

总的方法数是C(n,3),再减去不满足情况的

变形:y1*(x3-x2)+y2*(x1-x3)+y3*(x2-x1)

不满足情况的是奇+奇+奇……(1)

奇+偶+偶……(2)

(1)将式子以x整理的话,发现变成了偶+偶+偶,因此是不可能成立的

(2)总结出来4种不满足的情况:

(0,0) (0,1) (1,0)

(0,0) (0,1) (1,1)

(0,0) (1,0) (1,1)

(0,1) (1,0) (1,1)

就把整个问题变成o(n)的复杂度了~~~~

a274001809Accepted620K79MSG++852B2011-09-15 21:56:00
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>

long long map[5][5];
long long point[10010][3];

inline long long cal(long long n)
{
return n*(n-1)*(n-2)/6;
}

int main(void)
{
int T;
scanf("%d",&T);
int cas;
for(cas=1;cas<=T;cas++)
{
memset(map,0,sizeof(map));
printf("Scenario #%d:\n",cas);
long long n;
scanf("%lld",&n);
int i;
for(i=1;i<=n;i++)
{
scanf("%lld %lld",&point[i][0],&point[i][1]);
point[i][0]=(point[i][0]+100000)%2;
point[i][1]=(point[i][1]+100000)%2;
map[point[i][0]][point[i][1]]++;
}
long long total=cal(n);
total-=map[0][0]*map[0][1]*map[1][0];
total-=map[0][0]*map[0][1]*map[1][1];
total-=map[0][0]*map[1][0]*map[1][1];
total-=map[0][1]*map[1][0]*map[1][1];
printf("%lld\n\n",total);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: