POJ 1809 Regetni 奇偶性

來源:互聯網
上載者:User

題意:給你許n個點,可以從中任選三個點組成一個三角形。問這些三角形中面積為整數的有多少(包括0)。

題中給出一個面積公式:A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2 

題解:本質上我們只要讓x1y2 ,y1x2 , x2y3,y2x3, x3y1 ,y3x1這六項中奇數項的個數為偶數個,即0,2,4,6。

所以我們把點分類:奇奇,偶偶,奇偶,偶奇。逐個分析之後可以發現,只要保證三個頂點中至少有兩個屬於同一類,就能保證有偶數個
奇數項。

#include<cstdio>using namespace std;#define lint __int64int a[4];lint C ( int m, int n ){    if ( m < n ) return 0;    if ( m == n || n == 0) return 1;    lint mult = 1;    for ( int i = 1, j = m; i <= n; i++, j-- )        mult = mult * j / i;    return mult;}int main(){    int t, n, x, y;    scanf("%d",&t);    for ( int i = 1; i <= t; i++ )    {        scanf("%d",&n);        a[0] = a[1] = a[2] = a[3] = 0;        while ( n-- )        {            scanf("%d%d",&x,&y);            if ( (x&1) && (y&1) ) a[0]++;            else if ( !(x&1) && !(y&1) ) a[1]++;            else if ( (x&1) && !(y&1) ) a[2]++;            else a[3]++;        }        lint ret = 0;        ret += C(a[0],3)+C(a[1],3)+C(a[2],3)+C(a[3],3);        ret += C(a[0],2) * (a[1]+a[2]+a[3]);        ret += C(a[1],2) * (a[0]+a[2]+a[3]);        ret += C(a[2],2) * (a[1]+a[0]+a[3]);        ret += C(a[3],2) * (a[1]+a[2]+a[0]);        printf("Scenario #%d:\n%I64d\n\n",i,ret);    }    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.