Code Force 21B Intersection
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的更多相关文章
- 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窗口显示调试按钮 ...
- 【Code Force】Round #589 (Div. 2) D、Complete Tripartite
题目链接 大致题意 把一个图分成三块,要求任意两块之间是完全图,块内部没有连线 分析 首先根据块内没有连线可以直接分成两块 假定点1是属于块1的,那么所有与点1连接的点,都不属于块1:反之则是块1的 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- code force 1228C
算是一题普通数论+思维题吧. 大概很多人是被题意绕晕了. 思路: 首先常规操作求出X的质因子. 然后题目要求的是,X的每个质因子p,在g(i,p)的连乘.i∈[1,n]: 我们转换下思维,不求每一个g ...
- .htaccess 基础教程(三)RewriteCond标志符,RewriteRule适用的标志符
1.利用 .htaccess 防止盗链 如果不喜欢别人在他们的网页上链接自己的图片.文档的话,也可以通过htaccess的指令来做到.当然这样也可以对你的网站服务器压力变小! 这次先给出‘代码’,然后 ...
随机推荐
- redis基础之基本键值操作和使用(三)
前言 redis安装完毕后开始使用redis,先熟悉命令行操作. redis数据的类型 键:redis的所有的键都是string类型: 值:五种类型 string:字符串类型:一个string最大可以 ...
- linux 清内存
注意:首先我们需要使用sync指令,将所有未写的系统缓冲区写到磁盘中,包含已修改的 i-node.已延迟的块 I/O 和读写映射文件.否则在释放缓存的过程中,可能会丢失未保存的文件. 的值可以为0~3 ...
- JQM事件详解
在前文<使用 jQuery Mobile 与 HTML5 开发 Web App —— jQuery Mobile 默认配置与事件基础>中,Kayo 对 jQuery Mobile 事件的基 ...
- iPhone应用程序的启动过程
Phone的入口函数main,这之后它有是怎样启动应用程序,初始化的呢,这些都是通过 UIApplicationMain 来实现的. 其启动的流程图大致如下图所示: 1 int retVal = UI ...
- 03、同事分享课程的笔记 —《Android应用低功耗设计》
这是安卓组的同事一个月前分享的一节课程,听课时写了一下笔记,之前是写在本子上的,感觉内容挺不错 的,就保存在博客了吧,方便回看. 他曾经在就职于英特尔公司,是与芯片设计相关的,这课程标题虽然是与安卓相 ...
- C++之string的底层真的是用char数组来实现的么?
一.引言 遇到一个问题:使用加密库对数据进行加密,得到密文,使用string进行保存并传输,然后可以正确解密出来,但是使用string.c_str()进行参数传递则无法正确解密出明文. 原因是:密文中 ...
- [wifi]wifi模块操作
问题: 应用程序通过什么样的接口去修改wifi的账号和密码 应用程序如何控制wifi模块
- C/C++中printf和C++中cout的输出格式
一. Printf 输出格式 C中格式字符串的一般形式为: %[标志][输出最小宽度][.精度][长度]类型,其中方括号[]中的项为可选项.各项的意义介绍如下:1.类型类型字符用以表示输出数据的类型, ...
- python中的列表生成式
列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式. 举个例子,要生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, ...
- PHP导入导出excel表格图片的代码和方法大全
基本上导出的文件分为两种: 1:类Excel格式,这个其实不是传统意义上的Excel文件,只是因为Excel的兼容能力强,能够正确打开而已.修改这种文件后再保存,通常会提示你是否要转换成Excel文件 ...