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.
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.
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
- Intersection CodeForces - 21B(最大公约数gcd)
- CodeForces 21B Intersection
- CodeForces 21B Intersection (简单题)
- 求最大公约数(GCD)
- gcd() 最大公约数
- 求最大公约数(gcd)
- 最大公约数gcd()
- Gcd(最大公约数)
- gcd(int a, int b) //求最大公约数
- Codeforces 623 B. Array GCD
- Codeforces 623B:Array GCD
- CodeForces 623B Array GCD
- CodeForces 632B Co-prime Array 【GCD(互质)】
- Codeforces 623B Array GCD(枚举情况+dp)
- CodeForces 623 B.Array GCD(数论+dp)
- codeforces 901B GCD of Polynomials (数论+构造)
- hdoj2054又见GCD(GCD最大公约数)
- gcd算法整合(最大公约数)
- 10进制到任意进制的转换
- sublime插件docblockr的配置
- SpringBoot中Servlet&Listener&Filter的应用
- Job Hunting Suggestions
- 课程联系
- Intersection CodeForces - 21B(最大公约数gcd)
- 第五篇:赔率和盘口的特征之二
- 事务控制和锁定语句
- React-native 布局
- Android Studio 上传SVN忽略文件
- 使用butterknife轻松定义控件
- CCF 201612-4 压缩编码 区间dp(石子合并)+四边形不等式优化
- netty5.0的任务线程无法回收的问题
- IMP-00010: not a valid export file, header failed verification