poj 线段相交+暴力枚举

本文深入探讨了数据处理过程中的关键步骤与算法优化策略,包括数据结构选择、排序算法应用、动态规划优化等核心内容,旨在提升数据处理效率与算法执行速度。

数据水...没啥好讲的 模板+暴力秒的

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#define eps 1e-8
#define MAX 100007

using namespace std;

struct Point
{
    double x,y;
    Point():x(0),y(0){}
    Point( double a , double b )
        : x(a) , y (b){}
};

struct Line
{
    Point u,v;
}l[MAX];

int id = 1;
int mark[MAX];

int sig ( double d )
{
    return fabs(d) < eps ? 0 : d<0? -1:1;
}

double cross ( Point& o , Point& a , Point& b )
{
    return (a.x-o.x)*(b.y-o.y)-(b.x-o.x)*(a.y-o.y);
}

bool segCross ( Point& a , Point& b , Point& c , Point& d )
{
    double s1,s2;
    int d1 , d2 , d3 , d4;
    d1 = sig ( s1 = cross(a,b,c));
    d2 = sig ( s2 = cross(a,b,d));
    d3 = sig ( cross(c,d,a));
    d4 = sig ( cross(c,d,b));
    if ((d1^d2)==-2 && (d3^d4)==-2) return 1;
    return 0;
}

int record = 0;

void solve ( int i )
{
    double x1 , y1 , x2 , y2;
    scanf ( "%lf%lf%lf%lf" , &x1 , &y1 , &x2 , &y2 );
    l[i].u.x = x1 , l[i].u.y = y1 , l[i].v.x = x2 , l[i].v.y = y2;
    bool flag = true;
    for ( int j = 1 ; j < id ; j++ )
    {
        if ( !mark[j] ) continue;
        if ( segCross ( l[i].u,l[i].v,l[mark[j]].u,l[mark[j]].v ))
            if ( flag )
            {
                flag = false;
                mark[j] = i;
            }
            else mark[j] = 0, record--;
    }
    if ( flag ) mark[id++] = i , record++;
}

int main ( )
{
    int n;
    while ( ~scanf ( "%d" , &n ), n )
    {
        id = 1;
        record = 0;
        memset ( mark , 0 , sizeof ( mark ) );
        for ( int i = 1 ; i <= n ; i ++ ) solve ( i );
        printf ( "Top sticks:" );
        int current = 0;
        sort ( mark+1 , mark + id );
        for ( int i = 1 ; i < id ; i++ )
        {
            if ( !mark[i] ) continue;
            current++;
            if ( current < record )
            {
                printf ( " %d," , mark[i] );
            }
            else printf ( " %d.\n" , mark[i] );
        }
    }
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值