数据水...没啥好讲的 模板+暴力秒的
#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] );
}
}
}
本文深入探讨了数据处理过程中的关键步骤与算法优化策略,包括数据结构选择、排序算法应用、动态规划优化等核心内容,旨在提升数据处理效率与算法执行速度。
2601

被折叠的 条评论
为什么被折叠?



