洛谷P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler

P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler

题目描述

Farmer John has purchased the world‘s most loathesome hay baler. Instead of having a drive-roller that drives maybe an idler roller that drives the power take-off for the baler, it has N rollers (2 <= N <= 1050) which drive and are driven by various rollers.

FJ has meticulously cataloged data for each roller i: X_i,Y_i are the center of the roller (-5000 <= X_i <= 5000; -5000 <= Y_i <= 5000); R_i is the roller‘s radius (3 <= R_i <= 800). The drive-roller is located at 0,0; the baler power take-off is located at X_t,Y_t (numbers supplied in the input).

The drive-roller turns clockwise at 10,000 revolutions per hour. Your job is to determine the speeds of all the rollers that are in the power-train: from the drive-roller through the power take-off roller. Rollers that do not transfer power to the take-off roller are to be ignored. A roller of radius Rd that is turning at S rph and driving another roller of radius Rx will cause the second roller to turn at the speed -S*Rd/Rx (where the sign denotes whether the roller is turning clockwise or counterclockwise (anticlockwise for our British friends)).

Determine the power-train path and report the sum of the absolute values of all those rollers‘ speeds. All the rollers in the input set except the driver-roller are driven by some other roller; power is never transferred to a roller from more than one other roller.

Report your answer as an integer that is the truncated value after summing all the speeds.

Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互相作用,每个齿轮都可能驱动着多个齿轮。 FJ记录了对于每个齿轮i,记录了它的3个参数:X_i,Y_i表示齿轮中心的位置坐标(-5000 <= X_i <= 5000; -5000 <= Y_i <= 5000);R_i表示该齿轮的半径(3 <= R_i <= 800)。

驱动齿轮的位置为0,0,并且FJ也知道最终的工作齿轮位于X_t,Y_t。 驱动齿轮顺时针转动,转速为10,000转/小时。你的任务是,确定传动序列中所有齿轮的转速。传动序列的定义为,能量由驱动齿轮传送到工作齿轮的过程中用到的所有齿轮的集合。对能量传送无意义的齿轮都应当被忽略。

在一个半径为Rd,转速为S转/每小时的齿轮的带动下,与它相接的半径为Rx的齿轮的转速将为-S*Rd/Rx转/小时。S前的负号的意思是,一个齿轮带动的另一个齿轮的转向会与它的转向相反。

FJ只对整个传动序列中所有齿轮速度的绝对值之和感兴趣,你的任务也就相应转化成求这个值。机器中除了驱动齿轮以外的所有齿轮都被另外某个齿轮带动,并且不会出现2个不同的齿轮带动同一个齿轮的情况。

输入输出格式

输入格式:

  • Line 1: Three space-separated integers: N, X_t, and Y_t
  • Lines 2..N+1: Line i+1 describes roller i‘s properties: X_i, Y_i, and R_i

输出格式:

  • Line 1: A single integer that is the truncated version of the sum of
    the absolute value of the speeds of the rollers in the power-train
    including the drive-roller, all the driven rollers, and the power
    take-off roller.

输入输出样例

输入样例#1:

4 32 54
0 0 10
0 30 20
32 54 20
-40 30 20

输出样例#1:

20000

说明

Four rollers: the drive-roller at 0,0 with radius 10. It drives the roller above it at 0,30 with radius 20. That roller drives both the power take-off roller at 32,54 (r=20) and a random roller (not in the power train) at -40,30 (r=20).

Roller Radius Speed

1 (0,0) 10 10,000

2 (0,30) 20 -5,000

3 (32,54) 20 5,000



Sum of abs values: 20,000

bfs一下就可以了。

注意几个问题:

1、相切才能联动!

2、精度!用double!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <cmath>

const int sx = 1;
const int sy = 1;
const int K = 0;
const int MAXN = 1050 + 10;

int n,ex,ey;
int pre[MAXN];  //pre[i]琛ㄧずI鐨勯┍鍔ㄩ娇杞墍鍦ㄧ殑涓嬫爣浣嶇疆
int start;
int b[MAXN];

struct T
{
	int x,y,r;
	double energy, s;
}circle[MAXN];

inline bool IsPre(T& a, T& b)
{
	int d = (a.x - b.x)*(a.x - b.x)+ (a.y - b.y)*(a.y - b.y);
	int sum = a.r + b.r;
	return d == sum*sum;
}

void bfs()
{
	std::queue<T> q;
	q.push(circle[start]);
	b[start] = true;
	while(!q.empty())
	{
		T temp = q.front();
		q.pop();
		for(int i = 1;i <= n;i ++)
		{
			if( !b[i] && IsPre(circle[i], temp))
			{
				b[i] = true;
				circle[i].s =  temp.s * temp.r / circle[i].r;
				circle[i].energy = circle[i].s + temp.energy;
				if(circle[i].x  == ex && circle[i].y == ey)
				{
					printf("%d", (int)circle[i].energy);
					return ;
				}
				q.push(circle[i]);
			}
		}
	}
}

int main()
{
	freopen("data.txt", "r", stdin);
	scanf("%d%d%d", &n ,&ex, &ey);
	ex += K;
	ey += K;
	for(int i = 1;i <= n;i ++)
	{
		scanf("%d%d%d", &circle[i].x, &circle[i].y, &circle[i].r);
		circle[i].x += K;
		circle[i].y += K;
		if(circle[i].x == K && circle[i].y == K)
		{
			start = i;
			circle[i].s = 10000;
			circle[i].energy = 10000;
		}
	}
	bfs();
	return 0;
}
时间: 2024-08-09 10:42:37

洛谷P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler的相关文章

1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 574  Solved: 226[Submit][Status] Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互相作用,每个齿轮都可能驱动着多个齿轮. FJ

洛谷P2904 [USACO08MAR]跨河River Crossing 动态规划

洛谷P2904 [USACO08MAR]跨河River Crossing动态规划 区间DP f[ i ] 表示 将 i 头牛 运了过去,然后John 又返回所需要的最少时间 1 #include <cstdio> 2 #include <cstring> 3 #include <cmath> 4 #include <cstdlib> 5 #include <string> 6 #include <algorithm> 7 #inclu

洛谷 P2904 [USACO08MAR]跨河River Crossing

P2904 [USACO08MAR]跨河River Crossing 题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when he finds himself blocked by a river. A single raft is available for transportation. FJ knows that he must ride on the ra

洛谷—— P2904 [USACO08MAR]跨河River Crossing

https://www.luogu.org/problem/show?pid=2904 题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when he finds himself blocked by a river. A single raft is available for transportation. FJ knows that he must ride

BZOJ_1615_[Usaco2008_Mar]_The Loathesome_Hay Baler_麻烦的干草打包机_(模拟+宽搜/深搜)

描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1615 一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子带着转.求从主动轮到某一个轮子的路上所有轮子的转速的绝对值之和. 分析 从起点开始,枚举相接触的轮子,只要不是之前路上的(带着当前轮子转的)轮子,就继续往下走.宽搜深搜都可以. 注意: 1.%.0lf是会四舍五入的!所以要强制转化成int. 宽搜: 1 #include <bits/stdc++.h

bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

感觉自己像个智障 直接bfs 然而读入没判负号查了半小时.. 1 #include<cstdio> 2 #include<cctype> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 using namespace std; 7 #define maxn 1100 8 #define eps 1e-8 9 int n,tx,ty; 10 int st,ed; 11 in

洛谷P2900 [USACO08MAR]土地征用Land Acquisition

题目:https://www.luogu.org/problemnew/show/P2900 题目描述 Farmer John is considering buying more land for the farm and has his eye on N (1 <= N <= 50,000) additional rectangular plots, each with integer dimensions (1 <= width_i <= 1,000,000; 1 <=

洛谷P2420 让我们异或吧

P2420 让我们异或吧 161通过 450提交 题目提供者该用户不存在 标签洛谷原创云端↑ 难度普及/提高- 时空限制1s / 128MB 提交  讨论  题解 最新讨论更多讨论 倍增可做的吧 玄学 更改根节点得分不一样- 这题面似乎对一些群体不太友- 这题为什么没数据 C++选手注意了 题目描述 异或是一种神奇的运算,大部分人把它总结成不进位加法. 在生活中-xor运算也很常见.比如,对于一个问题的回答,是为1,否为0.那么: (A是否是男生 )xor( B是否是男生)=A和B是否能够成为情

洛谷 P1215 [USACO1.4]母亲的牛奶 Mother&#39;s Milk

题目描述 农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数, 最初,A和B桶都是空的,而C桶是装满牛奶的.有时,农民把牛奶从一个桶倒到另一个桶中,直到被灌桶装满或原桶空了.当然每一次灌注都是完全的.由于节约,牛奶不会有丢失. 写一个程序去帮助农民找出当A桶是空的时候,C桶中牛奶所剩量的所有可能性. 输入输出格式 输入格式: 单独的一行包括三个整数A,B和C. 输出格式: 只有一行,升序地列出当A桶是空的时候,C桶牛奶所剩量的所有可能性. 输入输出样例 输入样例#1: