平面图,两点右边当且仅当距离小于等于(d)。
求最大团。
(nle 100,dle 10^4,|x_i|,|y_i|le 10^4)
随机排列若干次,然后贪心找最大团就对了???
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 105
int n,k;
struct DOT{
int x,y;
} d[N];
int p[N];
int e[N][N];
int q[N],nq;
int ansq[N],ans;
bool judge(int x){
for (int i=1;i<=nq;++i)
if (!e[x][q[i]])
return 0;
return 1;
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d",&n,&k);
for (int i=1;i<=n;++i)
scanf("%d%d",&d[i].x,&d[i].y);
for (int a=1;a<=n;++a)
for (int b=1;b<=n;++b)
e[a][b]=(((d[a].x-d[b].x)*(d[a].x-d[b].x)+(d[a].y-d[b].y)*(d[a].y-d[b].y)<=k*k));
for (int i=1;i<=n;++i)
p[i]=i;
for (int T=1;T<=100000;++T){
random_shuffle(p+1,p+n+1);
nq=0;平面图,两点右边当且仅当距离小于等于$d$。
求最大团。
$nle 100,dle 10^4,|x_i|,|y_i|le 10^4$
---
随机排列若干次,然后贪心找最大团就对了???
---
```cpp
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 105
int n,k;
struct DOT{
int x,y;
} d[N];
int p[N];
int e[N][N];
int q[N],nq;
int ansq[N],ans;
bool judge(int x){
for (int i=1;i<=nq;++i)
if (!e[x][q[i]])
return 0;
return 1;
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d%d",&n,&k);
for (int i=1;i<=n;++i)
scanf("%d%d",&d[i].x,&d[i].y);
for (int a=1;a<=n;++a)
for (int b=1;b<=n;++b)
e[a][b]=(((d[a].x-d[b].x)*(d[a].x-d[b].x)+(d[a].y-d[b].y)*(d[a].y-d[b].y)<=k*k));
for (int i=1;i<=n;++i)
p[i]=i;
for (int T=1;T<=100000;++T){
random_shuffle(p+1,p+n+1);
nq=0;
for (int i=1;i<=n;++i)
if (judge(p[i]))
q[++nq]=p[i];
if (nq>ans){
ans=nq;
memcpy(ansq,q,sizeof(int)*(ans+1));
}
}
printf("%d
",ans);
for (int i=1;i<=ans;++i)
printf("%d ",ansq[i]);
return 0;
}
for (int i=1;i<=n;++i)
if (judge(p[i]))
q[++nq]=p[i];
if (nq>ans){
ans=nq;
memcpy(ansq,q,sizeof(int)*(ans+1));
}
}
printf("%d
",ans);
for (int i=1;i<=ans;++i)
printf("%d ",ansq[i]);
return 0;
}