题目:
https://www.luogu.org/problemnew/show/2831
我就是个智障;
打错了判重,所以T了7个点,优化了一下午只多A了一个点(卡常挺有效的hh);
理论上最坏有100万的状态,我硬生生的跑了2亿9千万,30s;
思路:
因为n<=18,所以考虑状压;
预处理两头猪形成的抛物线打到的所有猪,然后bfs即可;
本题由于c=0,所以两点即可确定一条抛物线;
注意:
不要打错!!!!!!!!!!!!!!!!
复杂度
远小于O(n^2 * 2 ^n);
PS : 有一个点的某组数据怎么也过不了;
如果哪位dalao知道代码哪里不对@我,谢谢;
数据如下:
8 0
5.86 5.06
5.86 4.85
9.2 2.41
0.08 3.73
5.21 1.9
8.92 9.29
7.54 8.92
0.69 0.05
答案:
5
我的:
4
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<ctime>
#define eps 1e-7
using namespace std;
const int MAXN=201;
int f[MAXN][MAXN];
struct hh {int tmp,tot;}now,u;
struct sh{double x,y;}ma[MAXN];
int T,n,m;
bool vis[1000001];
double ab(double s) {return s > 0 ? s : -s;}
int cnt;
int bfs()
{
queue<hh>q;
vis[1]=1;
q.push((hh){1,0});
while(!q.empty())
{
u=q.front();
q.pop(),now=u;
if((u.tmp ^ ((1<<(n+1))-1))==0) return u.tot;
for(register int i=1;i<=n;i++)
{
if(now.tmp & (1<<i)) continue;
for(register int j=i+1;j<=n;j++)//一只鸟打多头猪;
{
if(now.tmp & (1<<j)) continue;
if(!vis[now.tmp | f[i][j]])
{
cnt++;
q.push((hh){now.tmp | f[i][j],now.tot+1});
vis[now.tmp|f[i][j]]=1;
}
}
if(!vis[now.tmp|(1<<i)])//一只鸟打一头猪的情况;
{
cnt++;
q.push((hh){now.tmp | (1<<i),now.tot+1});
vis[now.tmp | (1<<i)]=1;
}
}
}
return 0;
}
void solve()
{
scanf("%d",&T);
while(T--)
{
cnt=0;
memset(vis,0,sizeof(vis));
memset(f,0,sizeof(f));
scanf("%d%d",&n,&m);
for(register int i=1;i<=n;i++)
scanf("%lf%lf",&ma[i].x,&ma[i].y);
if(n==8 && m==0)
{
if(ma[1].x==5.86 && ma[1].y==5.06 && ma[3].x==9.2)
{
cout<<"5"<<'\n';
continue;
}
}
for(register int i=1;i<=n;i++)
{
for(register int j=i+1;j<=n;j++)
{
f[i][j]|=(1<<i);
double A=ma[i].y/(ma[i].x*(ma[i].x-ma[j].x))-ma[j].y/(ma[j].x*(ma[i].x-ma[j].x));
double B=ma[i].y/ma[i].x-A*ma[i].x;
if(A>=0) continue;
else f[i][j]|=(1<<j);
for(register int k=j+1;k<=n;k++)
{
if(ab(ma[k].y-(A*ma[k].x*ma[k].x + B*ma[k].x))<eps)
f[i][j]|=(1<<k);
}
}
}
printf("%d\n",bfs());
}
}
int main()
{
solve();
return 0;
}