zoukankan      html  css  js  c++  java
  • Treasure Hunt POJ

    Treasure Hunt

    题目链接:https://vjudge.net/problem/POJ-1066

    题目:

     思路:将给的壁的每个端点与宝藏相连,求出当前线段与多少条线段相连,暴力求出最少相连数,瞎搞过了。。。一开始忘了当N==0情况,应当输出1

    // 
    // Created by HJYL on 2020/1/13.
    //
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<queue>
    #include<cmath>
    #define eps 1e-8
    #define Inf 0x7fffffff
    //#include<bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+100;
    struct Point{
        double x,y;
    };
    double min(double a, double b) { return a < b ? a : b; }
    
    double max(double a, double b) { return a > b ? a : b; }
    
    bool IsSegmentIntersect(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 <= eps && j * k <= eps;
    }
    
    int main()
    {
        int T;
        while(~scanf("%d",&T)) {
            Point a[maxn], b[maxn];
            for (int i = 0; i < T; i++)
                scanf("%lf%lf%lf%lf", &a[i].x, &a[i].y, &b[i].x, &b[i].y);
            Point bao;
            scanf("%lf%lf", &bao.x, &bao.y);
            int res[maxn] = {0};
            int pos = 0;
            for (int i = 0; i < T; i++) {
                for (int j = 0; j < T; j++) {
                    if (IsSegmentIntersect(bao, a[i], a[j], b[j]))
                        res[pos]++;
                }
                pos++;
            }
            for (int i = 0; i < T; i++) {
                for (int j = 0; j < T; j++) {
                    if (IsSegmentIntersect(bao, b[i], a[j], b[j]))
                        res[pos]++;
                }
                pos++;
            }
            sort(res, res + pos);
            if(T==0)
                printf("Number of doors = 1
    ");
            else
                printf("Number of doors = %d
    ", res[0]);
        }
        return 0;
    }
  • 相关阅读:
    个人介绍
    2021-03-16 助教小结
    2020软件工程作业05
    2020软件工程作业04
    2020软件工程作业03
    第二次作业 计划与执行
    从蓝天到名利 所有你想要的 都别随风去
    Android Task 相关
    Android ViewDragHelper源码解析
    android利用反射通过代码收缩通知栏
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12193554.html
Copyright © 2011-2022 走看看