题目描述

A wireless sensor network consists of autonomous sensors scattered in an environment where they monitor conditions such as temperature, sound, and pressure.

Samantha is a researcher working on the Amazon Carbon-dioxide Measurement (ACM) project. In this project, a wireless sensor network in the Amazon rainforest gathers environmental information. The Amazon rainforest stores an amount of carbon equivalent to a decade of global fossil fuel emissions, and it plays a crucial role in the world’s oxygen-transfer processes. Because of the huge size of this forest, changes in the forest affect not only the local environment but also global climate by altering wind and ocean current patterns. The goal of the ACM project is to help scientists better understand earth’s complex ecosystems and the impact of human activities.

Samantha has an important hypothesis and to test her hypothesis, she needs to find a subset of sensors in which each pair of sensors can communicate directly with each other. A sensor can communicate directly with any other sensor having distance at most \(d\) from it. In order for her experiments to be as accurate as possible, Samantha wants to choose as many sensors as possible.

As one does not simply walk into the Amazon, Samantha cannot add new sensors or move those that are currently in place. So given the current locations of the sensors, she needs your help to find the largest subset satisfying her criteria. For simplicity, represent the location of each sensor as a point in a two-dimensional plane with the distance between two points being the usual Euclidean distance.

输入格式

The input consists of a single test case. The first line contains two integers \(n\) and \(d\) (\(1 \le n \le 100\) and \(1 \le d \le 10\, 000\)), where \(n\) is the number of sensors available and \(d\) is the maximum distance between sensors that can communicate directly. Sensors are numbered \(1\) to \(n\). Each of the next \(n\) lines contains two integers \(x\) and \(y\) (\(-10\, 000\le x, y \le 10\, 000\)) indicating the sensor coordinates, starting with the first sensor.

求最大独立集,首先可以用爆搜/随机化(模拟退火)

然后来看正常解法。

直接做是很难做的,考虑枚举两个最远点。然后就有了这样一幅图。

只有不规则图形 ADB 和 ABC 中的点可能被选上。

然后 用初中数学 分析一下发现,如果将所有大于 \(d\) 的可选点连边,是一个二分图。因为只有在直线两边的点会连起来。

然后就是求二分图最大独立集的问题了。

理论复杂度 \(O(n^{4.5})\),理论上还可以除以 \(\omega\),但是本身常数就很小所以不用。

#include<bits/stdc++.h>
using namespace std;
const int N=105;
int n,d,vs[N],v[N][N],c,st[N],p[N],l,r,q[N],mx,k,mm[N],f[N][N];
struct node{
int x,y;
}t[N];
int dis(node x,node y)
{
return (x.x-y.x)*(x.x-y.x)+(x.y-y.y)*(x.y-y.y);
}
void dfs(int x,int y)
{
if(!~vs[x])
{
vs[x]=y;
for(int i=1;i<=n;i++)
if(v[x][i])
dfs(i,y^1);
}
}
int bfs()
{
memset(p,0,sizeof(p));
memset(mm,0,sizeof(mm));
p[q[l=r=1]=0]=1;
while(l<=r)
{
for(int i=0;i<=n+1;i++)
if(!p[i]&&v[q[l]][i])
p[q[++r]=i]=p[q[l]]+1;
++l;
}
return p[n+1];
}
int sou(int x)
{
if(x==n+1)
return 1;
for(int&i=mm[x];i<=n+1;i++)
{
if(v[x][i]&&p[i]==p[x]+1&&sou(i))
{
v[x][i]=0,v[i][x]=1;
return 1;
}
}
return 0;
}
int main()
{
scanf("%d%d",&n,&d);
for(int i=1;i<=n;i++)
scanf("%d%d",&t[i].x,&t[i].y);
st[mx=1]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<i;j++)
{
memset(v,0,sizeof(v));
memset(vs,-1,sizeof(vs));
int k=dis(t[i],t[j]);
c=0;
if(k>d*d)
continue;
for(int a=1;a<=n;a++)
{
if(dis(t[i],t[a])>k||dis(t[j],t[a])>k)
continue;
for(int b=1;b<=n;b++)
if(dis(t[b],t[j])<=k&&dis(t[b],t[i])<=k&&dis(t[a],t[b])>k&&a^b)
v[a][b]=1;
}
for(int a=1;a<=n;a++)
if(dis(t[i],t[a])<=k&&dis(t[j],t[a])<=k&&!~vs[a])
dfs(a,0);
for(int a=1;a<=n;a++)
{
if(vs[a]==0)
v[0][a]=1,++c;
else if(vs[a]==1)
{
for(int b=1;b<=n;b++)
v[a][b]=0;
v[a][n+1]=1,++c;
}
}
memcpy(f,v,sizeof(f));
int g=0,ans=0,tp=0;
while(bfs())
while(g=sou(0))
ans+=g;
if(c-ans>mx)
{
mx=c-ans;
for(int a=1;a<=n;a++)
if(vs[a]==0&&p[a]||vs[a]==1&&!p[a])
st[++tp]=a;
}
}
}
printf("%d\n",mx);
for(int i=1;i<=mx;i++)
printf("%d ",st[i]);
}

[ICPC2014WF]Sensor Network的更多相关文章

  1. 【BZOJ4080】【WF2014】Sensor Network [随机化]

    Sensor Network Time Limit: 2 Sec  Memory Limit: 128 MB[Submit][Status][Discuss] Description 魔法炮来到了帝都 ...

  2. 【Uvalive4960】 Sensor network (苗条树,进化版)

    [题意] 给出N个点,M条边,问这N个点形成的生成树的最大权值边-最小权值边的最小值 InputThe input consists of several test cases, separated ...

  3. 泛在传感器网络(Ubiquitous Sensor Network; USN)

    http://wiki.mbalib.com/wiki/%E6%B3%9B%E5%9C%A8%E4%BC%A0%E6%84%9F%E5%99%A8%E7%BD%91%E7%BB%9C 什么是泛在传感器 ...

  4. 2016级移动应用开发在线测试13-Location、Sensor & Network

    有趣有内涵的文章第一时间送达! 喝酒I创作I分享 生活中总有些东西值得分享 @醉翁猫咪  1. 充分利用智能手机的GPS定位信息,创造了O2O的商业模式,打通了线上与线下的信息流和商流,极大地推动了移 ...

  5. 【随机化】bzoj4080 [Wf2014]Sensor Network

    #include<cstdio> #include<algorithm> #include<cmath> using namespace std; typedef ...

  6. uvalive 4960 Sensor Network

    题意: 给出一个无向图,求一个生成树使得这个生成树的最大边与最小边之差最小,输出这个最小的差值.n的最大值为350. 思路: 这题不看题解想破头也不知道怎么写Orz. 暴力的做法是可以从大到小枚举边作 ...

  7. 【bzoj4080】[Wf2014]Sensor Network 随机化

    题目描述 魔法炮来到了帝都,除了吃特色菜之外,还准备去尝一尝著名的北京烤鸭.帝都一共有n(1<=1<=100)个烤鸭店,可以看成是二维平面内的点.不过由于魔法炮在吃烤鸭之前没有带钱,所以吃 ...

  8. bzoj 4080: [Wf2014]Sensor Network【瞎搞+随机化】

    参考:https://blog.csdn.net/YihAN_Z/article/details/73380387 一点都不想写正解.jpg random_shuffle一下然后贪心的加点,和ans取 ...

  9. UVALive - 4960 Sensor network(生成树+LCA)

    题目大意:给出N个点.M条边.问这N个点形成的生成树的最大权值边-最小权值边的最小值 解题思路:先排序,然后按生成树的kruscal算法进行加边,再维护一个最小权值边 加边的时候要考虑一下加下去的边是 ...

  10. Contiki Network Stack

    一.协议栈 主要有两大网络协议栈,uIP和Rime这两大协议栈(network stack): The uIP TCP/IP stack, which provides us with IPv4 ne ...

随机推荐

  1. Avalonia 实现聊天消息渲染、图文混排(支持Windows、Linux、信创国产OS)

       在实现即时通讯软件或聊天软件时,渲染文字表情.图文混排是一项非常繁琐的工作,再加上还要支持GIF动图.引用消息.撤回消息.名片等不同样式的消息渲染时,就更加麻烦了. 好在我们可以使用 ESFra ...

  2. API接口的设计思路

    ​ API接口设计是软件开发中非常重要的一环,良好的设计规范能够提高开发效率.减少问题和错误,并增强系统的可维护性和可扩展性.本文从程序员的视角,讨论一些常见的API接口设计规范. 一.遵循RESTf ...

  3. 如何使用关键词搜索API接口获取到快手的商品

    如果您想使用关键词搜索API接口获取到快手的商品,可以通过以下步骤实现: 1. 首先注册账号.根据文档申请相应的接口权限. 2. 确定需要使用的API接口.对于商品搜索,您可以查看相关的API文档以获 ...

  4. MD5&MD5盐值加密到BCryptPasswordEncoder

    MD5&MD5盐值加密 Message Digest algorithm5,信息摘要算法: 压缩性:任意长度的数据,算出的MD5值长度都是固定的 容易计算:从原数据计算出MD5值很容易 抗修改 ...

  5. 每日一题:AJAX进度监控(附可运行源码)

    1.什么是AJAX AJAX(Asynchronous JavaScript and XML)是一种用于在网页上进行异步通信的技术.它允许在不刷新整个页面的情况下,通过在后台与服务器进行数据交换来更新 ...

  6. 「codechef - STRQUER」Strange Queries

    link. 首先对原序列排序,考虑静态序列做法为:设 \(f(n,k\in\{0,1\})\) 为对于前 \(n\) 个数,第 \(n\) 个数否 / 是已经决策完毕的最优方案,转移即 \[\begi ...

  7. Oracle中的having()函数

    having函数用在group by子句的后面,对分组结果集进行条件筛选. 1.having子句包含聚合函数 /*列出平均工资在1000之上,并且最低工资不低于800的工作信息*/select job ...

  8. Python socket实现ftp文件下载服务

    简要 使用Python socket和多线程实现一个FTP服务下载.下面的示例是固定下载某一个任意格式文件. 仅仅为了展示如果使用socket和多线程进行文件下载 服务端代码 import socke ...

  9. 如何提高redux开发效率?当然是redux-tookit啦!

    前言 使用react-redux的朋友都经历过这种痛苦吧? 定义一个store仓库,首先创建各种文件,比如reducer.action.store...,然后 将redux和react连接使用.整个流 ...

  10. chatgpt 非常不稳定

      写一个飞机大战游戏       很抱歉,作为一名语言模型,我没有具体的编程功能,无法直接为您编写一个飞机大战游戏.不过,我可以为您提供一些创建飞机大战游戏的一般步骤和建议. 设计游戏元素 首先,您 ...