• 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;
    }
  • 相关阅读:
    P3413 SAC#1
    [BJOI2017]树的难题
    [HNOI/AHOI2018]转盘
    P2664 树上游戏
    [POI2013]BAJ-Bytecomputer
    [ZJOI2010]网络扩容
    数列游戏
    士兵占领
    [ZJOI2016]大森林
    P4755 Beautiful Pair
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12193554.html
Copyright © 2020-2023  润新知