zoukankan      html  css  js  c++  java
  • poj3429(有错)

    不知道为什么错。。

    /*************************************************************************
    > File Name: poj3429.cpp
    > Author: zhengnanlee
    > Mail: zhengnanlee@hotmail.com
    > Created Time: 2013年09月21日 星期六 09时10分12秒
    ************************************************************************/


    #include <iostream>
    #include <math.h>

    using namespace std;

    #define eps 1e-5
    #define zero(x) (((x)>0?(x):-(x))<eps)
    #define LL double

    struct point{ LL x, y; }p[105];

    int parallel(point u1, point u2, point v1, point v2)
    {
        return zero((u1.x - u2.x)*(v1.y - v2.y) - (v1.x - v2.x)*(u1.y - u2.y));
    }

    point intersection(point u1, point u2, point v1, point v2)
    {
        point ret = u1;
        LL t = ((u1.x - v1.x)*(v1.y - v2.y) - (u1.y - v1.y)*(v1.x - v2.x)) / ((u1.x - u2.x)*(v1.y - v2.y) - (u1.y - u2.y)*(v1.x - v2.x));
        ret.x += (u2.x - u1.x)*t;
        ret.y += (u2.y - u1.y)*t;
        return ret;
    }

    double distance(point a)
    {
        return sqrt(a.x * a.x + a.y * a.y);
    }

    int main()
    {
        int N;
        cin >> N;
        int countt = N;
        for (int i = 1; i <= N; i++)
        {
            cin >> p[i].x >> p[i].y;
        }
        int M;
        cin >> M;
        int cnt = 0;
        for (int i = 0; i < M; i++)
        {
            int a, b, c, d;
            cin >> a >> b >> c >> d;
            if (!parallel(p[a], p[b], p[c], p[d]))
            {
                point temp = intersection(p[a], p[b], p[c], p[d]);
                p[++countt] = temp;
                if (zero(distance(temp))) cnt++;
            }
        }
        cout << cnt << endl;
    }


  • 相关阅读:
    vim 多个文件切换
    Ruby 格式化代码 vim
    Ruby 配置vimrc
    print puts p
    开机跳过开机选择系统的选项界面
    Linux学习笔记:rm删除文件和文件夹
    Linux学习笔记:ps -ef、ps aux、kill -9
    Linux学习笔记:ctrl+z、ctrl+c、ctrl+d的区别
    Shell学习笔记:<<EOF子命令
    Linux学习笔记:crontab定时任务
  • 原文地址:https://www.cnblogs.com/riskyer/p/3331402.html
Copyright © 2011-2022 走看看