Code Force 21B Intersection
2016-04-16 11:27
288 查看
B. Intersection
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Examples
input
1 1 0
2 2 0
output
-1
input
1 1 0
2 -2 0
output
1
模拟
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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.
Examples
input
1 1 0
2 2 0
output
-1
input
1 1 0
2 -2 0
output
1
模拟
#include <iostream> #include <string.h> #include <stdlib.h> #include <algorithm> #include <math.h> #include <stdio.h> using namespace std; int a1,b1,c1; int a2,b2,c2; int main() { scanf("%d%d%d%d%d%d",&a1,&b1,&c1,&a2,&b2,&c2); if((a1==0&&b1==0&&c1!=0)||(a2==0&&b2==0&&c2!=0)) {cout<<0<<endl;return 0;} if((a1==0&&b1==0&&c1==0)||(a2==0&&b2==0&&c2==0)) {cout<<-1<<endl;return 0;} if((a1==0&&a2!=0)||(a1!=0&&a2==0)) {cout<<1<<endl;return 0;} if(a1==0&&a2==0) { double k1=1.0*c1/b1; double k2=1.0*c2/b2; if(k1==k2) {cout<<-1<<endl;return 0;} else {cout<<0<<endl;return 0;} } if((b1==0&&b2!=0)||(b1!=0&&b2==0)) {cout<<1<<endl;return 0;} if(b1==0&&b2==0) { double k1=1.0*c1/a1; double k2=1.0*c2/a2; if(k1==k2) {cout<<-1<<endl;return 0;} else {cout<<0<<endl;return 0;} } if((b1==0&&a2==0)||(b2==0&&a1==0)) {cout<<1<<endl;return 0;} double k1=1.0*a1/b1; double k2=1.0*a2/b2; if(k1==k2) { if((c1==0&&c2!=0)||(c1!=0&&c2==0)) {cout<<0<<endl;return 0;} if(c1==0&&c2==0) { double kk1=1.0*a1/a2; double kk2=1.0*b1/b2; if(kk1==kk2) {cout<<-1<<endl;return 0;} else {cout<<0<<endl;return 0;} } else { double kk1=1.0*a1/a2; double kk2=1.0*b1/b2; double kk3=1.0*c1/c2; if(kk1==kk2&&kk2==kk3) {cout<<-1<<endl;return 0;} else {cout<<0<<endl;return 0;} } } else { cout<<1<<endl;return 0; } }
相关文章推荐
- Linux学习笔记知识点(二)
- 演示获取请求头信息
- 利用IOS的异常处理机制来做崩溃统计分析
- LeetCode——022
- java之路径分隔符介绍
- 改革春风吹满地 计算几何
- Layer 1: 深入分析Parquet列式存储格式
- POJ 1679 The Unique MST【最小生成树问题相关】
- 演示request的常用方法
- VS 应用模板 所交税和实发工资的运算
- Java线程创建和启动
- 比较好的按键处理方法以及实例
- Android_TextView中部分文字响应事件
- 数据库理论之ACID和BASE的比较
- codevs 1191 数轴染色 区间更新加延迟标记
- 第6周项目4-静态成员应用
- VS 星期作业 if else的应用 做一个受不受异性欢迎的小程序
- Code Forces 22B Bargaining Table
- iOS CocoaPods安装和使用
- java.net.UnknownHostException