牛客假日团队赛7 A:Oh Those Rollers (暴力)

链接:https://ac.nowcoder.com/acm/contest/997/A
 

题目描述

Farmer John has installed a new winch that gives him mechanical advantage when lifting bales of hay into the barn. The winch was manufactured by the Rube Goldberg Winch Company and has way too many rollers to make any sense at all. The winch has a huge steel plate with a number of rollers whose ultimate source of power is the drive-roller whose location FJ has denoted as the origin (0,0). This roller drives a roller that drives another roller, etc. etc. until the final roller is driven. FJ is trying to find that final roller and wants to know which one it is.
FJ has recorded the xi,yi (-5,000 <= xi <= 5,000; -5,000 <= yi <= 5,000) coordinates and the radius ri (3 <= ri <= 1024) of each of the N (2 <= N <= 1080) rollers. Tell him the x,y coordinate of the last roller in the chain (the roller that is driven but drives no other roller). Every roller except the drive-roller is driven by exactly one other roller.

输入描述:

* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 describes roller i with three space separated integers: xi, yi, and ri

输出描述:

* Line 1: A single line with two space-separated integers that are respectively the x,y coordinates of the last roller in the chain of driven rollers.

示例1

输入

复制

3
0 0 30
30 40 20
-15 100 55

输出

复制

-15 100

说明

Three rollers. First is at the origin with radius 30. It drives the roller at (30,40) whose radius is 20. That roller in turn drives the third roller located at (-15,100) with radius 55.

题意分析:

有n个齿轮,其中位于0 0的是主齿轮,除了主齿轮外其他每个齿轮都要依靠其他齿轮才能转动,求最后一个齿轮的位置。

解题思路:

暴力找只有一个相邻齿轮且不是主齿轮的位置。

#include <stdio.h>
#include <queue>
#define N 2000
using namespace std;
struct date {
	int x;
	int y;
	int r;
}a[N];
bool book[N];
int main()
{
	int i, n, u, ans, s;
	scanf("%d", &n);
	queue<int>q;
	for (i = 1; i <= n; i++)
	{
		scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].r);
		if (a[i].x == 0 && a[i].y == 0)
		{
			s = i;
			q.push(i);
			book[i] = true;
		}	
	}
	ans = 0;
	while (!q.empty())
	{
		u = q.front();
		q.pop();
		int t = 0;
		for (i = 1; i <= n; i++)
		{
			if ((a[u].x - a[i].x) * (a[u].x - a[i].x) + (a[u].y - a[i].y) * (a[u].y - a[i].y) == (a[i].r + a[u].r)*(a[i].r + a[u].r))
			{
				t++;
				if (book[i] == false)
				{
					book[i] = true;
					q.push(i);
				}
			}
		}
		if (t == 1 && u!=s)
		{
			ans = u;
			break;
		}
	}
	printf("%d %d\n", a[ans].x, a[ans].y);

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张宜强

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值