洛谷P3416 Moocast S

题目描述

Farmer John's NN cows (1 \leq N \leq 2001≤N≤200) want to organize an emergency"moo-cast" system for broadcasting important messages among themselves.

Instead of mooing at each-other over long distances, the cows decide to equip themselves with walkie-talkies, one for each cow. These walkie-talkies each have a limited transmission radius -- a walkie-talkie of power PP can only transmit to other cows up to a distance of PP away (note that cow A might be able to transmit to cow B even if cow B cannot transmit back, due to cow A's power being larger than that of cow B). Fortunately, cows can relay messages to one-another along a path consisting of several hops, so it is not necessary for every cow to be able to transmit directly to every other cow.

Due to the asymmetrical nature of the walkie-talkie transmission, broadcasts from some cows may be more effective than from other cows in their ability toreach large numbers of recipients (taking relaying into account). Please help the cows determine the maximum number of cows that can be reached by a broadcast originating from a single cow.

约翰农场主的N(1<=N<=200)头奶牛想建立一个紧急情况下的“哞哞广播”系统,这样它们就可以在自己中间广播重要信息。

奶牛们想让每头牛装备上一个对讲机,而不是在长距离中向另一头奶牛“哞哞”乱叫。这些对讲机每台都有各自的有效传输半径——一个拥有P能量的对讲机只能向距离在P以内的牛发送信息(注意可能出现A牛对讲机的能量比B牛的大,而A牛可以给B牛发送信息,但B牛不能传回信息)。幸运的是,奶牛们可以通过其他奶牛中继,沿着一条跳跃的路径传递信息,因此每个奶牛不必要直接向每个其他奶牛传播。

由于对讲机的费堆成性质,来自一些奶牛的广播可能比其他奶牛的广播能够达到更多的接受者(考虑中继的情况)的能力更有效。请帮助奶牛确定来自单个奶牛的广播可以达到的奶牛的最大数量。

输入格式

The first line of input contains NN.

<p>The next NN lines each contain the xx and yy coordinates of a single cow ( integers in the range 0 \ldots 25,0000…25,000) followed by pp, the power of the walkie-talkie held by this cow.

第一行输入包括N。

下面的N行,每一行都包括了一只牛的坐标(x,y),(x,y为整数并且在0...25,000的范围内)和这只牛所持有对讲机的能量P。

输出格式

Write a single line of output containing the maximum number of cows a broadcast from a single cow can reach. The originating cow is included in this number.

输出一行,表示从来自单个奶牛的广播可以达到的奶牛的最大数量。开始的牛也包括在这个数量中。

输入输出样例

输入 #1复制

4
1 3 5
5 4 3
7 2 1
6 1 1

输出 #1复制

3

上代码:

#include<bits/stdc++.h>
using namespace std;

const int maxn = 205;
int ans, n;
int vis[maxn];

//结构体
struct node {
	int x, y, p;
}a[maxn];

//返回两点距离
double dis(node a, node b) { 
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

//搜索
void dfs(int cur) { //cur代表目前的位置
	for (int i = 1; i <= n; i++) {
		if (dis(a[cur], a[i]) <= a[cur].p && !vis[i]) { //判断条件:如果下一个顶点可以被达到,而且以前没有被达到过
			vis[i] = 1; //标记
			dfs(i); //递归
		}
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i].x >> a[i].y >> a[i].p; //输入
	}
	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		memset(vis, 0, sizeof(vis)); //别忘记清零
		vis[i] = 1;
		dfs(i);
		for (int j = 1; j <= n; j++) 
			if (vis[j]) cnt++;
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值