zoukankan      html  css  js  c++  java
  • Pick-up sticks

    题目大意:有一个木棒,按照顺序摆放,求出去上面没有被别的木棍压着的木棍.....

     
    分析:可以维护一个队列,如果木棍没有被压着就入队列,如果判断被压着,就让那个压着的出队列,最后把这个木棍放进队列,不过速度并不快,枚举才是最快的......据说是任意时刻没有超过1000个top sticks.....很难注意到。
     
    代码如下:
    =====================================================================================================================================
    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<iostream>
    #include<math.h>
    using namespace std;
    
    const int MAXN = 1e5+7;
    const double EPS = 1e-8;
    
    struct point
    {
        double x, y;
        point(double x=0, double y=0):x(x),y(y){}
        point operator - (const point &t) const{
            return point(x-t.x, y-t.y);
        }
        double operator * (const point &t) const{
           double ans = x*t.y - y*t.x;
    
            if(ans > EPS)return 1;
            if(fabs(ans) < EPS)return 0;
            return -1;
        }
    };
    struct segment
    {
        point A, B;
        segment(point A=0, point B=0):A(A), B(B){}
    
    };
    bool Intersect(segment a, segment b)
    {
        return (a.A-a.B)*(b.A-a.B)+(a.A-a.B)*(b.B-a.B) == 0;
    }
    
    int used[MAXN], ans[MAXN];
    segment seg[MAXN];
    
    bool Find(int k, int N)
    {
        for(int i=k+1; i<=N; i++)
        {
            if(Intersect(seg[k], seg[i]) && Intersect(seg[i], seg[k]))
                return true;
        }
    
        return false;
    }
    
    int main()
    {
        int N;
    
        while(scanf("%d", &N) != EOF && N)
        {
            for(int i=1; i<=N; i++)
            {
                scanf("%lf%lf%lf%lf", &seg[i].A.x, &seg[i].A.y, &seg[i].B.x, &seg[i].B.y);
                used[i] = false;
            }
    
            int k=0;
    
            for(int i=1; i<=N; i++)
            {
                used[i] = Find(i, N);
                if(!used[i])ans[k++] = i;
            }
    
            printf("Top sticks: ");
            for(int i=0; i<k-1; i++)
                printf("%d, ", ans[i]);
            printf("%d.
    ", ans[k-1]);
        }
    
        return 0;
    }
  • 相关阅读:
    Guru's Guide to SQL Server Architecture and Internals
    如何诊断修正17883,17884,17887,17888错误
    Debugging a SQL Server query with WinDbg
    Windbg调试Sql Server 进程
    SQL SERVER 技术博客 外文
    sql server book
    SQL Server Debugging with WinDbg – an Introduction
    Concurrency(Locking, Blocking and Row Versioning)
    如何自学Android, 教大家玩爆Android
    Storage protocol stacks
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4790347.html
Copyright © 2011-2022 走看看