2013 - ECJTU 暑期训练赛第七场-problem-H

H - O.O
Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second 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.

Sample Input

Input
1 1 0
2 2 0
Output
-1
Input
1 1 0
2 -2 0
Output
1
这题就是给出两条条直线的方程(即点集)的例如:Ax+By+C=0的A、B、C判断这两个方程有几个公共解(或者几个点集是公共的)
AC代码+解释:
#include<iostream>//判断两条条直线的方程(即点集)的例如:Ax+By+C=0的A、B、C判断这两个方程有几个公共解
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;
int panduan(double x,double y,double z)
{
    if(x==0&&y==0)
    {
        if(z==0)return 1;
        else return 2;
    }
    return 3;
}
int main()
{
    double a1,a2,b1,b2,c1,c2;
    int k1,k2;
    while(cin>>a1>>b1>>c1>>a2>>b2>>c2)
    {
        k1=panduan(a1,b1,c1);//如果两直线其中有一条A,B,C全为0,那么那条直线就不存在,那么另一条直线就有无数解或者两条直线都不存在也是无数解
        k2=panduan(a2,b2,c2);
        if((k1==1&&k2!=2)||(k1!=2&&k2==1))
        {
            cout<<-1<<endl;
            continue;
        }
        if(a1==0&&a2==0&&b1!=0&&b2!=0)//当A等于0,此时方程可以写成:y=(-C)/B
        {
            if(c1/b1==c2/b2)//如果相等即两条直线共线
            {
                cout<<-1<<endl;
                continue;
            }
            else
            {
                cout<<0<<endl;//否则就平行
                continue;
            }
        }
        if(a1!=0&&a2!=0&&b1==0&&b2==0)//同理,当B=0,此时方程可以写成:x=(-C)/A;
        {
            if(c1/a1==c2/a2)//如果相等则两直线共线
            {
                cout<<-1<<endl;
                continue;
            }
            else//否则两直线平行
            cout<<0<<endl;
            continue;
        }
        if(a1!=0&&b1!=0&&a2!=0&&b2!=0)//如果A和B都不为0,那么方程可以化成:y=(-A/B)*x+(-C/B)
        {
            if(a1/b1==a2/b2&&c1/b1==c2/b2)//如果都相等则还是两直线共线
            {
                cout<<-1<<endl;
                continue;
            }
            else if(a1/b1==a2/b2)//否则如果只有斜率(即(-A/B))相等,那么就是平行了
            {
                cout<<0<<endl;
                continue;
            }
        }
        if((a1==0&&b1==0&&c1!=0)||(a2==0&&b2==0&&c2!=0))//如果A和B都等于0,而C不为0,那么这两直线就不是两直线即不合法
        {
            cout<<0<<endl;
            continue;
        }
        cout<<1<<endl;//除此之外就只能相交了
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值