题解:P13667 [GCPC 2023] Balloon Darts
刚开始 老师 也没看出来,他给出的思路是把一个点以一根线旋转 180 度,那么就枚举这样的范围中哪个点的情况是最优的,但是这个思路时间复杂度过高(其实是我精度调不出来),下面来看一下正解。
考虑一下朴素的搜索是先以此确定三条直线,然后看看是否能穿过所有点,但是这样的做法时间复杂度达到
因为对于
总结一下就是,对于平面上的任意
代码很好写,这里直接附上。
#include<bits/stdc++.h>
#define endl "\n"
#define Robin ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
typedef long long LL;
struct P {
LL x, y;
P(LL x=0, LL y=0) : x(x), y(y) {}
};
bool col(P a, P b, P c) {
return (b.x-a.x)*(c.y-a.y) == (b.y-a.y)*(c.x-a.x);
}
bool f(vector<P> p, int k) {
int n=p.size();
if(n<=k) return 1;
if(!k) return 0;
if(k==1) {
for(int i=2;i<n;i++)
if(!col(p[0],p[1],p[i])) return 0;
return 1;
}
int m=min(n,k+1);
for(int i=0;i<m;i++)
for(int j=i+1;j<m;j++) {
vector<P> t;
for(int x=0;x<n;x++)
if(!col(p[i],p[j],p[x])) t.push_back(p[x]);
if(f(t,k-1)) return 1;
}
return 0;
}
int main() {
int n; cin>>n;
vector<P> p(n);
for(int i=0;i<n;i++) cin>>p[i].x>>p[i].y;
cout<<(f(p,3)?"possible":"impossible")<<endl;
return 0;
}