zoukankan      html  css  js  c++  java
  • POJ-2563

    Time Limit: 3000MS   Memory Limit: 65536K
    Total Submissions: 10364   Accepted: 3842

    Description

    Stan has n sticks of various length. He throws them one at a time on the floor in a random way. After finishing throwing, Stan tries to find the top sticks, that is these sticks such that there is no stick on top of them. Stan has noticed that the last thrown stick is always on top but he wants to know all the sticks that are on top. Stan sticks are very, very thin such that their thickness can be neglected.

    Input

    Input consists of a number of cases. The data for each case start with 1 <= n <= 100000, the number of sticks for this case. The following n lines contain four numbers each, these numbers are the planar coordinates of the endpoints of one stick. The sticks are listed in the order in which Stan has thrown them. You may assume that there are no more than 1000 top sticks. The input is ended by the case with n=0. This case should not be processed.

    Output

    For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should be listed in order in which they were thrown.

    The picture to the right below illustrates the first case from input.

    Sample Input

    5
    1 1 4 2
    2 3 3 1
    1 -2.0 8 4
    1 4 8 2
    3 3 6 -2.0
    3
    0 0 1 1
    1 0 2 1
    2 0 3 1
    0
    

    Sample Output

    Top sticks: 2, 4, 5.
    Top sticks: 1, 2, 3.
    

    Hint

    Huge input,scanf is recommended.

    Source

    /**
              题意:给出n条线段,然后取没有被覆盖的;
              做法:计算几何(线段相交)
    **/
    #include <iostream>
    #include<cmath>
    #include<algorithm>
    #include<string.h>
    #include<stdio.h>
    #define maxn 100000+ 10
    using namespace std;
    int n,m;
    int mmap[maxn];
    const double eps = 1e-8;
    const  double PI = acos(-1.0);
    int sgn(double x)
    {
        if(fabs(x) < eps) return 0;
        if(x < 0) return -1;
        return 1;
    }
    struct Point
    {
        double x;
        double y;
        Point() {}
        Point(double _x,double _y)
        {
            x = _x;
            y = _y;
        }
        Point operator - (const Point &b) const
        {
            return Point(x - b.x,y - b.y);
        }
        double operator ^(const Point &b) const
        {
            return x*b.y - y*b.x;
        }
        double  operator *(const Point &b) const
        {
            return x*b.x + y*b.y;
        }
    } point[maxn];
    struct Line
    {
        Point s;
        Point e;
        Line() {}
        Line(Point _s,Point _e)
        {
            s = _s;
            e = _e;
        }
    } line[maxn];
    bool inter(Line l1,Line l2)
    {
        return max(l1.s.x ,l1.e.x) >= min(l2.s.x,l2.e.x) &&
               max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
               max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
               max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
               sgn((l2.s - l1.e) ^(l1.s-l1.e) )*sgn((l2.e - l1.e)^(l1.s-l1.e) )<= 0 &&
               sgn((l1.s - l2.e) ^(l2.s- l2.e)) *sgn((l1.e - l2.e) ^(l2.s - l2.e)) <=0;
    }
    int main()
    {
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE
        int n;
        while(~scanf("%d",&n))
        {
            if(n == 0) break;
            double  a,b,c,d;
            for(int i=0; i<n; i++)
            {
                scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
                line[i] = Line(Point(a,b),Point(c,d));
            }
            memset(mmap,0,sizeof(mmap));
            for(int i=0; i<n; i++)
            {
                for(int j=i+1; j<n; j++)
                {
                    if(inter(line[i],line[j]))
                    {
                        mmap[i] = 1;
                        break;
                    }
                }
            }
            printf("Top sticks: ");
            int res = 0;
            for(int i=0; i<n; i++)
            {
                if(mmap[i] == 0)
                {
                    if(res != 0) printf(", ");
                    printf("%d",i+1);
                    res++;
                }
            }
            printf(".
    ");
        }
        return 0;
    }
  • 相关阅读:
    python字符串,列表,字典的常用方法
    Python【第一课】 Python简介和基础
    python中index()与find()的差异
    tomcat学习笔记2
    tomcat学习笔记1
    haproxy学习笔记
    高可用工具keepalived学习笔记
    ngx_http_upstream_module模块学习笔记
    nginx的rewrite,gzip,反向代理学习笔记
    nginx学习笔记1
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4434432.html
Copyright © 2011-2022 走看看