poj 1809 Regetni

 

这是一个组合数学题:

题意:就是给你n个点,任选3个点判断A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2是否为整数(0也算),并计算这样的组合存在多少个;

思路 A = y1*(x3-x2) + y2*(x1-x3) + y3*(x2-x1);只有A为偶数时才成立;

那么只有两种情况成立:1 : 奇 + 奇 + 偶   2 : 偶 + 偶 + 偶;

那么我们就可以把点化成0,1的类型:即 (x,y)= (x&1,y&1);

我么在找规律得:如果存在2中以上的类型相同,那么这种情况一定是偶数;

 

View Code
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<vector>
#include<string>
#define LL long long
using namespace std;
inline LL Solve( int num[][2],int n )
{
    LL sum = 0;
   for( int i =0 ;  i < 4; i ++ )
   {
         LL temp = num[i>>1][i&1];
         sum += temp*(temp-1)*(temp-2)/6 + temp*(temp-1)*(n-temp)/2; 
   }    
   return sum;
}
int main(  )
{
    int num[2][2],T,x,y,n;
    while( scanf( "%d",&T )==1 )
    {
        for( int Case = 1 ; Case <= T ; Case++ )
        {
              scanf( "%d",&n );
              memset( num , 0 , sizeof( num ) );
              for( int i = 0 ; i < n ; i ++ )
              {
                   scanf( "%d%d",&x,&y );
                   num[x&1][y&1]++;        
              }    
              printf( "Scenario #%d:\n%I64d\n\n",Case,Solve( num  ,n ) );
        }    
    }
    //system( "pause" );
    return 0;
}

       

posted @ 2012-08-12 10:24  wutaoKeen  阅读(220)  评论(0)    收藏  举报