前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Code Force 21B Intersection

Code Force 21B Intersection

作者头像
ShenduCC
发布2018-04-26 16:17:51
6280
发布2018-04-26 16:17:51
举报
文章被收录于专栏:算法修养算法修养

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

模拟

代码语言:javascript
复制
#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;
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-04-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档