• POJ 1066 Treasure Hunt


    题目大意:求到到目标点至少需要穿过几道墙。

    题目思路:暴力循环,计算各个点(不要忘记四角)与目标点的连线穿过多少条线段,取最小值。

    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<math.h>
    #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<queue>
    #define MAXSIZE 100005
    #define INF 0x3f3f3f3f
    #define LL long long
    
    using namespace std;
    
    //求到到目标点至少需要穿过几道墙。
    
    struct node
    {
        double x1,y1,x2,y2;
    } well[MAXSIZE];
    
    struct node1
    {
        double x,y;
    } p[MAXSIZE];
    
    double Cross(double x1,double y1,double x2,double y2,double x3,double y3)
    {
        return (x1-x2)*(y2-y3)-(x2-x3)*(y1-y2);
    }
    
    void Solve(int n,int cns,double ex,double ey)
    {
        int minn=INF,sum;
        for(int i=1; i<cns; i++)
        {
            sum=0;
            for(int j=1; j<=n; j++)
            {
                double op1=Cross(p[i].x,p[i].y,well[j].x1,well[j].y1,well[j].x2,well[j].y2)
                            *Cross(ex,ey,well[j].x1,well[j].y1,well[j].x2,well[j].y2);
                double op2=Cross(well[j].x1,well[j].y1,p[i].x,p[i].y,ex,ey)
                            *Cross(well[j].x2,well[j].y2,p[i].x,p[i].y,ex,ey);
                if(op1<0 && op2<0)
                    sum++;
            }
            minn=min(minn,sum);
        }
        printf("Number of doors = %d
    ",minn+1);
    }
    
    int main()
    {
        int n,cns=1;
        double x1,y1,x2,y2,ex,ey;
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1; i<=n; i++)
            {
                scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
                well[i].x1=x1;
                well[i].y1=y1;
                well[i].x2=x2;
                well[i].y2=y2;
                p[cns].x=x1;
                p[cns++].y=y1;
                p[cns].x=x2;
                p[cns++].y=y2;
            }
    
            p[cns].x=0;
            p[cns++].y=0;
            p[cns].x=0;
            p[cns++].y=100;
            p[cns].x=100;
            p[cns++].y=100;
            p[cns].x=100;
            p[cns++].y=0;
    
            scanf("%lf%lf",&ex,&ey);
            Solve(n,cns,ex,ey);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    MongoDB 安装及其配置
    hdu 1241 Oil Deposits
    2014ACM/ICPC亚洲区北京站
    hdu 5901 count prime & code vs 3223 素数密度
    hdu 2191 珍惜现在,感恩生活
    FOJ 2181 快来买肉松饼
    hdu 5384 Danganronpa
    hdu 2222 Keywords Search
    hdu 1300 Pearls
    2016.2.24. 《构建之法》开始阅读
  • 原文地址:https://www.cnblogs.com/alan-W/p/6016054.html
Copyright © 2020-2023  润新知