poj 1809 Regetni(数学)

Regetni
Time Limit: 3000MS Memory Limit: 30000K
Total Submissions: 1595 Accepted: 615

Description

Background 
Hello Earthling. We're from the planet Regetni and need your help to make lots of money. Maybe we'll even give you some of it. 
You see, the problem is that in our world, everything is about integers. It's even enforced by law. No other numbers are allowed for anything. That said, it shouldn't surprise you that we use integer coordinate systems to plan our cities. So far only axis-aligned rectangular plots of land have been sold, but our professor Elgnairt recently had the revolutionary idea to sell triangular plots, too. We believe that the high society will love this concept and it'll make us rich. 
Unfortunately the professor patented his idea and thus we can't just do it. We need his permission and since he's a true scientist, he won't give it to us before we solve some damn riddle. Here's where you come in,because we heard that you're a genius. 

Problem 
The professor's riddle goes like this: Given some possible corners for the triangles, determine how many triangles with integral size can be built with them. Degenerated triangles with empty area (i.e. lines) have to be counted, too, since 0 is an integer. To be more precise, count the number of triangles which have as corners three different points from the input set of points. All points in a scenario will be distinct, i.e. there won't be duplicates. Here are some examples: 

Example a) shows a triangle with integral area (namely 3), b) shows one with non-integral size, c) shows a degenerated triangle with empty area (i.e. zero, so count it!), d) shows four points of which you can choose any three to build an integral area triangle and e) shows four points where you can't build any integral area triangles at all. 
Hint: The area A of a triangle with corners (x1, y1), (x2, y2) and (x3, y3) can be computed like this: 
A=|x1y2 - y1x2 + x2y3 - y2x3 + x3y1 - y3x1|/2 
Try to make clever use of this formula.

Input

The first line contains the number of scenarios. For each scenario, there is one line containing first the number N of distinct points in that scenario (0 <= N <= 10000) and after that N pairs of integers, each pair describing one point (xi, yi) with -100000 <= xi, yi <= 100000. All these numbers are separated by single blanks.

Output

Start the output for every scenario with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the number of triangles with integral area whose three distinct corners are among the points given. Terminate the output for each scenario with a blank line.

Sample Input

6
3 0 0 2 0 1 -3
3 0 0 2 1 1 -3
3 0 0 2 2 3 3
4 0 0 2 0 0 2 2 2
4 0 0 1 0 0 1 1 1
9 0 0 0 1 0 2 1 0 1 1 1 2 2 0 2 1 2 2

Sample Output

Scenario #1:
1

Scenario #2:
0

Scenario #3:
1

Scenario #4:
4

Scenario #5:
0

Scenario #6:
48

Source

TUD Programming Contest 2003, Darmstadt, Germany

题意:给定一些整数坐标的点,问能组成的整数面积的情况数
题解:最大限度的利用题目所给的公式,分析公式可知,组合数只和点的奇偶有关,那么只需记录4种情况的点的数目,奇 奇,偶,偶 奇,偶偶,然后把所有无顺序组合情况列出来,排除不能得出整数结果的,然后直接打公式出来就行了

#include<stdio.h>
long long x,y,ans,zz,zo,oz,oo;
int main()
{
    int i,n,t,cas=1;

    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        ans=zz=zo=oz=oo=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d%I64d",&x,&y);
            if(x&1)
            {
                if(y&1) oo++;
                else oz++;
            }
            else
            {
                if(y&1) zo++;
                else zz++;
            }
        }
        ans+=zz*(zz-1)*(zz-2)/6;
        ans+=zo*(zo-1)*(zo-2)/6;
        ans+=oz*(oz-1)*(oz-2)/6;
        ans+=oo*(oo-1)*(oo-2)/6;

        ans+=zz*(zz-1)*zo/2;
        ans+=zz*(zz-1)*oz/2;
        ans+=zz*(zz-1)*oo/2;

        ans+=zo*(zo-1)*zz/2;
        ans+=zo*(zo-1)*oz/2;
        ans+=zo*(zo-1)*oo/2;

        ans+=oz*(oz-1)*zz/2;
        ans+=oz*(oz-1)*zo/2;
        ans+=oz*(oz-1)*oo/2;

        ans+=oo*(oo-1)*zz/2;
        ans+=oo*(oo-1)*zo/2;
        ans+=oo*(oo-1)*oz/2;

        printf("Scenario #%d:\n",cas++);
        printf("%I64d\n\n",ans);
    }

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值