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

模拟

#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;
}
}

Code Force 21B Intersection的更多相关文章

  1. pycharm debug后会出现 step over /step into/step into my code /force step into /step out 分别表示

    1.debug,全部打印 2.打断点debug,出现单步调试等按钮,只运行断点前 3.setup over 调试一行代码 4.setup out 运行断点后面所有代码 5.debug窗口显示调试按钮 ...

  2. 【Code Force】Round #589 (Div. 2) D、Complete Tripartite

    题目链接 大致题意 把一个图分成三块,要求任意两块之间是完全图,块内部没有连线 分析 首先根据块内没有连线可以直接分成两块 假定点1是属于块1的,那么所有与点1连接的点,都不属于块1:反之则是块1的 ...

  3. code force 424 A - Office Keys

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  4. code force 403C.C. Andryusha and Colored Balloons

    C. Andryusha and Colored Balloons time limit per test 2 seconds memory limit per test 256 megabytes ...

  5. code force 403B.B. The Meeting Place Cannot Be Changed

    B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...

  6. code force 401B. Game of Credit Cards

    B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  7. Code Force 429B Working out【递推dp】

    Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the ...

  8. code force 1228C

    算是一题普通数论+思维题吧. 大概很多人是被题意绕晕了. 思路: 首先常规操作求出X的质因子. 然后题目要求的是,X的每个质因子p,在g(i,p)的连乘.i∈[1,n]: 我们转换下思维,不求每一个g ...

  9. .htaccess 基础教程(三)RewriteCond标志符,RewriteRule适用的标志符

    1.利用 .htaccess 防止盗链 如果不喜欢别人在他们的网页上链接自己的图片.文档的话,也可以通过htaccess的指令来做到.当然这样也可以对你的网站服务器压力变小! 这次先给出‘代码’,然后 ...

随机推荐

  1. SMBus总线概述

    1.概述: 系统管理总线是一种两线制接口.它基于I2C 总线原理演变而来,可以认为是简化版的I2C总线. SMBus最初是应用到智能电池,如电池充电器和一个微控制器.其提供一个系统和电源管理相关的任务 ...

  2. 2014 Multi-University Training Contest 1/HDU4864_Task(贪心)

    解题报告 题意,有n个机器.m个任务. 每一个机器至多能完毕一个任务.对于每一个机器,有一个最大执行时间Ti和等级Li,对于每一个任务,也有一个执行时间Tj和等级Lj.仅仅有当Ti>=Tj且Li ...

  3. [转] James A. whittaker:经营成功的测试生涯

    James A. whittaker:经营成功的测试生涯 2015-05-13 James Whittaker James Whittaker is an energetic and passiona ...

  4. python模块之XlsxWriter 详解

    Xlsx是python用来构造xlsx文件的模块,可以向excel2007+中写text,numbers,formulas 公式以及hyperlinks超链接. 可以完成xlsx文件的自动化构造,包括 ...

  5. 记一次log4j日志导致线上OOM问题案例

    最近一个服务突然出现 OutOfMemoryError,两台服务因为这个原因挂掉了,一直在full gc.还因为这个问题我们小组吃了一个线上故障.很是纳闷,一直运行的好好的,怎么突然就不行了呢... ...

  6. lua工具库penlight--08额外的库(一)

    额外的库 在这一节中的库不再被认为是Penlight的核心部分,但在需要时,仍提供专门的功能. 简单的输入的模式 Lua 的字符串模式匹配是非常强大,通常您将不需要传统的正则表达式库.即便如此,有时  ...

  7. Android Studio运行程序,检测不到(夜神、Genymotion)模拟器

    用了统一给的android studio,运行程序,检测不到模拟器(夜神). 又新建了一个系统的模拟器,运行,提示ANDROID_SDK_ROOT is undefined 在环境变量中配置之后,夜神 ...

  8. Am335x 应用层之SPI操作

    SPI接口有四种不同的数据传输时序,取决于CPOL和CPHL这两位的组合.图1中表现了这四种时序, 时序与CPOL.CPHL的关系也可以从图中看出. 图1 CPOL是用来决定SCK时钟信号空闲时的电平 ...

  9. ApplicationListener接口中的onApplicationEvent被调用两次解决方式

    Spring容器初始化完毕后,调用BeanPostProcessor这个类,这个类实现ApplicationListener接口,重写onApplicationEvent方法, 方法中就是我们自己要在 ...

  10. 算法优化:rgb向yuv的转化最优算法

    朋友曾经给我推荐了一个有关代码优化的pdf文档<让你的软件飞起来>,看完之后,感受颇深.为了推广其,同时也为了自己加深印象,故将其总结为word文档.下面就是其的详细内容总结,希望能于己于 ...