BZOJ 4080 Wf2014 Sensor Network randomization, bzojwf2014

Source: Internet
Author: User
Tags bitset

BZOJ 4080 Wf2014 Sensor Network randomization, bzojwf2014

On a given plane N Point, find the largest point set, so that the distance between the two is not more D

It's useless to add any pruning to the search T ......

Good randomization Method

A random sequence is added in order, and then the answer is updated.

Is it said to be reliable? It's almost done after writing it.

#include <bitset>#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 110using namespace std;typedef bitset<M> abcd;struct Point{    int x,y;    friend istream& operator >> (istream &_,Point &p)    {        return scanf("%d%d",&p.x,&p.y),_;    }    friend bool operator < (const Point &p1,const Point &p2)    {        return p1.x < p2.x ;    }    friend int Distance(const Point &p1,const Point &p2)    {        return (p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y) ;    }}points[M];int n,d;abcd a[M];abcd now,able,ans;int main(){    int i,j;    cin>>n>>d;    for(i=1;i<=n;i++)        cin>>points[i];    for(i=1;i<=n;i++)        for(j=i+1;j<=n;j++)            if(Distance(points[i],points[j])<=d*d)                a[i][j]=a[j][i]=true;    static int order[M];    for(i=1;i<=n;i++)    {        able[i]=true;        order[i]=i;    }    for(j=1;j<=1000;j++)    {        abcd able=::able;        now.reset();        for(i=1;i<=n;i++)            if(able[order[i]])            {                now[order[i]]=true;                able&=a[order[i]];            }        if(now.count()>ans.count())            ans=now;        random_shuffle(order+1,order+n+1);    }    cout<<ans.count()<<endl;    for(i=1;i<=n;i++)        if(ans[i])            printf("%d ",i);    return 0;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.