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)的复杂度了~~~~
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)的复杂度了~~~~
a27400 | 1809 | Accepted | 620K | 79MS | G++ | 852B | 2011-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; }
相关文章推荐
- POJ_1809_Regetni(组合数学)
- poj 1809 Regetni(数学)
- Paths on a Grid POJ 1942 组合数学
- poj 1019 Number Sequence 第i位上的数字 (组合数学)
- POJ 2645 Boastin' Red Socks(组合数学)
- poj_1942 Paths on a Grid(组合数学 求C(a+b, a))
- POJ 1809 Regetni 奇偶性
- POJ1850 组合数学
- poj 1850 Code (组合数学)
- poj 1850 Code 组合数学
- poj 2356 Find a multiple(组合数学:鸽巢原理)
- 【组合数学】POJ_1850_Code
- POJ-1715 Hexadecimal Numbers 组合数学
- POJ 1850:Code 组合数学
- POJ 3252 组合数学?
- (组合数学3.1.1.1)POJ 1146 ID Codes(字典序法)
- poj_3252 Round Numbers(组合数学)
- poj_1850 Code(组合数学/dfs)
- POJ 题目1850 Code(组合数学)
- POJ 1942-Paths on a Grid(组合数学)