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);
        }
    }


  • 相关阅读:
    Codeforces Round #311 (Div. 2)题解
    firefox 被劫持hao123 主页
    国有航空为啥“放下身段”读春秋?
    ORACLE中常见SET指令
    最大概率法分词及性能測试
    怎样利用JDBC连接并操作Oracle数据库
    hdu5240
    代码调试过程中easy遇到的问题
    最简单的基于FFmpeg的AVDevice样例(读取摄像头)
    FPGA 功耗结构设计
  • 原文地址:https://www.cnblogs.com/Open_Source/p/1904960.html
Copyright © 2011-2022 走看看