zoukankan      html  css  js  c++  java
  • hdu-1147(跨立实验)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1147

    思路:判断每条线段,如果将要输入的线段和已经有的线段相交,则这条线段不算。

    参考文章:https://blog.csdn.net/hexianhao/article/details/51254487

    判断两条线段是否相交:https://www.cnblogs.com/wuwangchuxin0924/p/6218494.html

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    using namespace std;
    struct Node{
        double x1,y1,x2,y2;
    };
    struct N{
        int x,y;
    };
    int pd(Node t1,Node t2)
    {
        N a,b,c,d;  
        a.x=t1.x1;a.y=t1.y1;
        b.x=t1.x2;b.y=t1.y2;
        c.x=t2.x1;c.y=t2.y1;
        d.x=t2.x2;d.y=t2.y2;
        double u=(c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
        double v=(d.x-a.x)*(b.y-a.y)-(b.x-a.x)*(d.y-a.y);
        if(u*v>0) return 0;
        double w=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y);
        double z=(b.x-c.x)*(d.y-c.y)-(d.x-c.x)*(b.y-c.y);
        if(w*z>0) return 0;
        return 1;
    }
    const int maxn = 100100;
    Node vc[maxn];
    int vis[maxn];
    int main(void)
    {
        int n,i,j;
        while(scanf("%d",&n)&&n)
        {
            memset(vis,0,sizeof(vis));
            for(i=1;i<=n;i++)
            {
                scanf("%lf%lf%lf%lf",&vc[i].x1,&vc[i].y1,&vc[i].x2,&vc[i].y2);
            }
            int num=0;
            for(i=1;i<n;i++)
            {
                for(j=i+1;j<=n;j++)
                {
                    if(pd(vc[i],vc[j]))
                    {
                        vis[i]=1;num++;break;
                    }
                }
            }
            num=n-num;
            printf("Top sticks:");
            for(j=0,i=1;i<=n;i++)
            {
                if(vis[i]==0)
                {
                    j++;
                    if(j==num) printf(" %d.
    ",i);
                    else printf(" %d,",i);
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    istio 配置解读
    docker 不同版本 添加--insecure-registry
    Ingress 暴露tcp端口
    jenkins 调用 k8s api
    十五项指标衡量DevOps是否成功
    关于使用镜像仓库的思考
    Jenkins pipeline:pipeline 语法详解
    lvm xfs 扩容
    看到了一个pipeline例子,
    私有仓库harbor安装包括https
  • 原文地址:https://www.cnblogs.com/2018zxy/p/9914750.html
Copyright © 2011-2022 走看看