Intersection CodeForces - 21B(最大公约数gcd)

来源:互联网 发布:centos ssh 连不上 编辑:程序博客网 时间:2024/05/18 01:06

You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0.

Write the program which finds the number of points in the intersection of two given sets.

Input

The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive.

Output

Print the number of points in the intersection or -1 if there are infinite number of points.


水题,分类讨论即可。

#include<stdio.h>#include<math.h>#include<ctype.h>#include<stdlib.h>#include<algorithm>using namespace std;int main(){    int a1,b1,a2,b2;    double c1,c2;    while(~scanf("%d%d%lf%d%d%lf",&a1,&b1,&c1,&a2,&b2,&c2))    {        if((a1||b1)&&(a2||b2))        {            int gcd1=__gcd(a1,b1),gcd2=__gcd(a2,b2);            a1/=gcd1,b1/=gcd1,c1=c1/(double)gcd1;            a2/=gcd2,b2/=gcd2,c2=c2/(double)gcd2;            if(a1==a2&&b1==b2&&c1==c2)                printf("-1\n");            else if(a1==a2&&b1==b2&&c1!=c2)                printf("0\n");            else                printf("1\n");        }        else if(((!a1)&&(!b1)&&(c1))||((!a2)&&(!b2)&&(c2)))            printf("0\n");        else if(((!a1)&&(!b1)&&(!c1))||((!a2)&&(!b2)&&(!c2)))            printf("-1\n");        else            printf("0\n");    }}


0 0
原创粉丝点击