POJ 1269 Intersecting Lines

题目链接

题意:

判断两条直线的关系:相交 平行 重合

代码:

#include <stdio.h>
#include <cstring>
#include <cmath>
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <algorithm>
#include <deque>
#include <iomanip>
#include <vector>
#define mem(arr, num) memset(arr, 0, sizeof(arr))
#define _for(i, a, b) for (int i = a; i <= b; i++)
#define __for(i, a, b) for (int i = a; i >= b; i--)
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const ll INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 5000 + 5;
string str[3] = {"POINT", "LINE", "NONE"};
int main()
{
    int n;
    cin >> n;
    cout << "INTERSECTING LINES OUTPUT" << endl;
    while (n--)
    {
        double x1, x2, x3, x4, y1, y2, y3, y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        double _x1 = x2 - x1, _x2 = x4 - x3, _y1 = y2 - y1, _y2 = y4 - y3;
        if (_x1 == 0 || _x2 == 0)
        { //斜率不存在;
            if (_x1 == 0 && _x2 == 0)
            {
                if (x1 == x3)
                    cout << str[1] << endl;
                else
                    cout << str[2] << endl;
            }
            else if (_x2 != 0)
            {
                cout << str[0] << " " << setiosflags(ios::fixed) << setprecision(2) << 
                    x1 << " " << (_y2 / _x2) * x1 + (y3 - (_y2 / _x2)*x3) << endl;
            }
            else if (_x1 != 0){
                cout << str[0] << " " << setiosflags(ios::fixed) << setprecision(2) << 
                    x3 << " " << (_y1 / _x1) * x3 + (y1 - (_y1 / _x1)*x1) << endl;
            }
        }
        else {
            double k1 = _y1/_x1, k2 = _y2/_x2;
            double b1 = y1 - k1*x1, b2 = y3 - k2 * x3;
            if(k1 == k2){
                if(b1 == b2)
                    cout << str[1] << endl;
                else cout << str[2] << endl;
            }
            else {
                cout << str[0] << " " << setiosflags(ios::fixed) << setprecision(2) << 
                    (b2-b1)/(k1-k2) << " " <<k1 * (b2-b1)/(k1-k2) + b1 <<endl;
            }
        }
    }
    cout << "END OF OUTPUT" << endl;
    return 0;
}

 

转载于:https://www.cnblogs.com/GHzcx/p/8798696.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值