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.
水题,分类讨论即可。
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"); } }
相关文章推荐
- Educational Codeforces Round 21 F. Card Game(网络流之最大点权独立集)
- codechef GCD2 无穷大数的最大公约数
- 51Nod 1011 最大公约数GCD
- 求a和b的最大公约数 gcd(a ,b)= gcd(b, a%b) 例:gcd(36,24) =gcd(24, 12 ) =gcd(12, 0 )
- Summary: gcd最大公约数、lcm最小公倍数算法
- 【解题报告】Educational Codeforces Round 21
- 1011 最大公约数GCD(51NOD基础题)
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
- HDU--IMNU集训四:Lowest Common Multiple Plus n个数的最大公约数 递归啊GCD啊之类的
- HDU 2028最小公倍数LCM 最大公约数GCD
- 求GCD(最大公约数)的算法
- Code[VS] 1012 最小公倍数与最大公约数
- 51Nod-1011-最大公约数GCD
- 最大公约数算法GCD
- Codeforces Round #410 (Div.2) C.Mike and gcd problem-数学
- Educational Codeforces Round 21(A-D)(水题 + 尺取 + 构造 + multiset优化)
- 最大公约数(GCD)的Euclid算法
- GCD(最大公约数)的函数
- 【Codeforces Round 274 (Div 2)A】【暴力 水题】Expression 三个数值运算使得结果最大
- Codeforces Round #430-01字典树&类异或最大值-D. Vitya and Strange Lesson