• IOI2021集训队作业 210AI Sensor Network


    平面图,两点右边当且仅当距离小于等于(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;
    

    }

  • 相关阅读:
    c++字符串
    iOS调用相册
    cocos2d-x中有一个JniHelper类详细使用
    iOS 字符串应用
    c++调用java
    iOS调用相册、相机、上传等问题
    win32中GBK、UTF8的互转
    SQL Server海量数据查询代码优化建议
    JSON中的[]和{}
    数据库范式
  • 原文地址:https://www.cnblogs.com/jz-597/p/13965821.html
Copyright © 2020-2023  润新知