zoukankan      html  css  js  c++  java
  • hdoj1086 You can Solve a Geometry Problem too

    #include<iostream>
    #include
    <stdio.h>
    using namespace std;
    int n;
    typedef 
    struct {        //定义点
        double x, y;
    } point;
    struct segment {
        point fir, end;
    };
    segment pnt[
    100];
    bool inter(point & a, point & b, point & c, point & d)
    {
        
    if (min(a.x, b.x) > max(c.x, d.x) || min(a.y, b.y) > max(c.y, d.y) ||
        min(c.x, d.x) 
    > max(a.x, b.x) || min(c.y, d.y) > max(a.y, b.y))
        
    return 0;
        
    double h, i, j, k;
        h 
    = (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
        i 
    = (b.x - a.x) * (d.y - a.y) - (b.y - a.y) * (d.x - a.x);
        j 
    = (d.x - c.x) * (a.y - c.y) - (d.y - c.y) * (a.x - c.x);
        k 
    = (d.x - c.x) * (b.y - c.y) - (d.y - c.y) * (b.x - c.x);
        
    return h * i <= 0.0000000001 && j * k <= 0.0000000001;
    }

    int main()
    {
        
    while (scanf("%d"&n) != EOF && n) {
        
    int sum = 0;
        
    for (int i = 0; i < n; ++i) {
            scanf(
    "%lf%lf%lf%lf"&pnt[i].fir.x, &pnt[i].fir.y,
              
    &pnt[i].end.x, &pnt[i].end.y);
        }
        
    for (int i = 0; i < n; ++i) {
            
    for (int j = i + 1; j < n; ++j) {
            
    if (inter(pnt[i].fir, pnt[i].end, pnt[j].fir, pnt[j].end))
                sum
    ++;
            }
        }
        printf(
    "%d\n", sum);
        }
    }


  • 相关阅读:
    SPLAY,LCT学习笔记(五)
    SPLAY,LCT学习笔记(四)
    SPLAY,LCT学习笔记(三)
    NOI 2012 随机数生成器
    SPLAY,LCT学习笔记(二)
    SPLAY,LCT学习笔记(一)
    bzoj 1503 郁闷的出纳员
    bzoj 1112 poi 2008 砖块
    bzoj 1064 noi2008 假面舞会题解
    数论知识点总结(noip范围)
  • 原文地址:https://www.cnblogs.com/Open_Source/p/1904960.html
Copyright © 2011-2022 走看看