题目大意
给定坐标系上的
n
个点,每个点有一个单位时间的位移
现在选择一个非0的整数时刻,在这个时刻选择一条直线,将这个直线经过的所有点删掉。
最多能删掉几个点。
多组数据。
Data Constraint
n≤100
题解
我们先枚举三个不同的点,显然我们可以解出它们共线的时刻(利用向量的叉积来判断,解一个一元二次方程)。
然后再统计有多少个点在这条直线上。
时间复杂度: O(T×n4)
SRC
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std ;
#define N 100 + 10
typedef long long ll ;
const double eps = 1e-8 ;
struct Point {
ll x , y ;
Point ( ll X = 0 , ll Y = 0 ) { x = X , y = Y ; }
} ;
struct Tank {
Point w , v ;
} P[N] ;
map < pair < int , int > , int > Q ;
int n , ans ;
ll t1 , t2 ;
Point operator + ( Point a , Point b ) { return Point( a.x + b.x , a.y + b.y ) ; }
Point operator - ( Point a , Point b ) { return Point( a.x - b.x , a.y - b.y ) ; }
Point operator * ( int lmuda , Point a ) { return Point( lmuda * a.x , lmuda * a.y ) ; }
ll operator * ( Point a , Point b ) { return a.x * b.y - a.y * b.x ; }
bool operator == ( Point a , Point b ) { return ( a.x == b.x && a.y == b.y ) ; }
bool operator != ( Point a , Point b ) { return !( a.x == b.x && a.y == b.y ) ; }
ll ABS( ll x ) { return x < 0 ? -x : x ; }
bool Calc( ll A , ll B , ll C ) {
if ( A == 0 ) {
if ( B == 0 ) {
if ( C == 0 ) { t1 = t2 = 2 ; return 1 ; }
return 0 ;
}
if ( ABS(C) % ABS(B) != 0 ) return 0 ;
t1 = t2 = -C / B ;
return 1 ;
}
ll delta = B * B - 4ll * A * C ;
if ( delta < 0 ) return 0 ;
ll d = sqrt(delta) + eps ;
if ( d * d != delta ) return 0 ;
t1 = -B + d ;
if ( ABS(t1) % ABS((2ll * A)) != 0 ) t1 = -1 ;
else t1 /= 2ll * A ;
t2 = -B - d ;
if ( ABS(t2) % ABS((2ll * A)) != 0 ) t2 = -1 ;
else t2 /= 2ll * A ;
return 1 ;
}
void Solve( Tank p1 , Tank p2 , Tank p3 , ll t ) {
Point a = Point( p1.w.x + t * p1.v.x , p1.w.y + t * p1.v.y ) ;
Point b = Point( p2.w.x + t * p2.v.x , p2.w.y + t * p2.v.y ) ;
Point c = Point( p3.w.x + t * p3.v.x , p3.w.y + t * p3.v.y ) ;
Point l = Point( 0 , 0 ) ;
if ( a != b ) l = b - a ;
else if ( a != c ) l = c - a ;
else if ( b != c ) l = c - b ;
int tot = 0 ;
for (int i = 1 ; i <= n ; i ++ ) {
Tank p = P[i] ;
Point d = Point( p.w.x + t * p.v.x , p.w.y + t * p.v.y ) ;
if ( d == a || d == b || d == c ) { tot ++ ; continue ;}
if ( l.x == 0 && l.y == 0 ) continue ;
Point _l = d - a ;
if ( _l * l == 0 ) { tot ++ ; continue ;}
_l = a - d ;
if ( _l * l == 0 ) tot ++ ;
}
ans = max( ans , tot ) ;
}
int main() {
scanf( "%d" , &n ) ;
while ( n ) {
ans = min( 2 , n ) ;
Q.clear() ;
for (int i = 1 ; i <= n ; i ++ ) {
scanf( "%lld%lld%lld%lld" , &P[i].w.x , &P[i].w.y , &P[i].v.x , &P[i].v.y ) ;
pair < int , int > tp = make_pair( P[i].w.x , P[i].w.y ) ;
if ( Q.find( tp ) != Q.end() ) ans = max( ans , Q[tp] + 1 ) ;
Q[tp] += 1 ;
}
for (int i = 1 ; i <= n ; i ++ ) {
Point P1 = P[i].w ;
for (int j = 1 ; j < i ; j ++ ) {
Point P2 = P[j].w ;
for (int k = 1 ; k < j ; k ++ ) {
Point P3 = P[k].w ;
Point d1 = Point( P1.x - P2.x , P[i].v.x - P[j].v.x ) ;
Point d2 = Point( P1.y - P2.y , P[i].v.y - P[j].v.y ) ;
Point d3 = Point( P3.x - P2.x , P[k].v.x - P[j].v.x ) ;
Point d4 = Point( P3.y - P2.y , P[k].v.y - P[j].v.y ) ;
ll A = d1.y * d4.y - d2.y * d3.y ;
ll B = d4.x * d1.y + d1.x * d4.y - d2.x * d3.y - d3.x * d2.y ;
ll C = d1.x * d4.x - d2.x * d3.x ;
if ( !Calc( A , B , C ) ) continue ;
if ( t1 > 0 ) Solve( P[i] , P[j] , P[k] , t1) ;
if ( t2 > 0 && t1 != t2 ) Solve( P[i] , P[j] , P[k] , t2 ) ;
if ( ans == 18 ) {
ans = 100 ;
ans ++ ;
ans -- ;
}
}
}
}
printf( "%d\n" , ans ) ;
scanf( "%d" , &n ) ;
}
return 0 ;
}
以上.