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;
    }
  • 相关阅读:
    <转> 解决异常:IllegalStateException: Fragment <ThisFragment> is not currently in the FragmentManager
    带你走进Android Afinal框架的世界
    Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
    Myeclipse启动不了的解决方法
    select 禁止 选择
    jquery的clone方法应用于textarea和select的bug修复不能copy值,clone id重复的解决
    玩javaweb的web.xml编译路径
    程序员笔记之设计(一)
    Eclipse清除SVN密码
    Java 最简单的批处理
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4434432.html
Copyright © 2011-2022 走看看