您的位置:首页 > 其它

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

2017-01-06 13:28 267 查看
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)&&(!b
4000
2)&&(!c2)))
printf("-1\n");
else
printf("0\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数学