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];
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()
{
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;
}

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

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

    P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler 细节题.$O(n^{2})$的$bfs$可过. #include<iostream> ...

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

    传送门 题目问的是从出发点一直跑到终点的一条链上所有齿轮的速度和 其他的不用考虑 直接搜就好了 注意求的是绝对值之和,不是和的绝对值,所以不用考虑方向问题 注意 N<=1050 数组不要只开10 ...

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

    题目 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MB Desc ...

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

    1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit:  ...

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

    Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...

  6. 洛谷P2900 [USACO08MAR]土地征用Land Acquisition(动态规划,斜率优化,决策单调性,线性规划,单调队列)

    洛谷题目传送门 用两种不一样的思路立体地理解斜率优化,你值得拥有. 题意分析 既然所有的土地都要买,那么我们可以考虑到,如果一块土地的宽和高(其实是蒟蒻把长方形立在了平面上)都比另一块要小,那么肯定是 ...

  7. 【BZOJ】1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机(模拟+bfs)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1615 这种题..... #include <cstdio> #include <c ...

  8. bzoj1615 麻烦的干草打包机 BFS

    Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...

  9. 洛谷 P2900 [USACO08MAR]土地征用Land Acquisition 解题报告

    P2900 [USACO08MAR]土地征用Land Acquisition 题目描述 约翰准备扩大他的农场,眼前他正在考虑购买N块长方形的土地.如果约翰单买一块土 地,价格就是土地的面积.但他可以选 ...

随机推荐

  1. c语言学习笔记 - 指针和字符串

    前面学习了字符串是一种字符数组,又知道了指针变量和数组的关系,这里来看一下指针和字符串的关系. #include <stdio.h> int main(void){ char str = ...

  2. Java常用英语汇总(面试必备)

    Java常用英语汇总(面试必备) abstract (关键字)             抽象 ['.bstr.kt] access                            vt.访问,存 ...

  3. JEECMS 自定义标签

    CMS 是”Content Management System” 的缩写,意为” 内容管理系统”. 内容管理系统是企业信息化建设和电子政务的新宠,也是一个相对较新的市场.对于内容管理,业界还没有一个统 ...

  4. Spring注解驱动(下)

    9.@PropertySource 加载配置文件 在xml中 我们加载property配置文件,是使用 <context:property-placeholder location=" ...

  5. Python学习day04 - Python基础(2)数据类型基础

    <!doctype html>day04 - 博客 figure:last-child { margin-bottom: 0.5rem; } #write ol, #write ul { ...

  6. Vuejs之Component slot 插槽详解

    Vuejs的component的数据进行了沙箱隔离,除js全局变量如Math, Date之类外无法访问用户自定义的变量,所以使用component写组件或嵌套组件时明白变量的访问非常重要 编译作用域 ...

  7. MySQL8.0.17 - 初探 Clone Plugin

    MySQL8.0.17推出了一个重量级的功能:clone plugin.允许用户可以将当前实例进行本地或者远程的clone.这在某些场景尤其想快速搭建复制备份或者在group replication里 ...

  8. 《Python机器学习及实践:从零开始通往Kaggle竞赛之路》

    <Python 机器学习及实践–从零开始通往kaggle竞赛之路>很基础 主要介绍了Scikit-learn,顺带介绍了pandas.numpy.matplotlib.scipy. 本书代 ...

  9. 软件-DiskSpeekUp:DiskSpeekUp(磁盘整理工具)

    ylbtech-软件-DiskSpeekUp:DiskSpeekUp(磁盘整理工具) Disk SpeedUP是一个完全自由和极快的碎片整理工具来分析,碎片整理和优化计算机性能的峰值磁盘. 它是安全没 ...

  10. 转载 ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(一) 整理基础数据

    ASP.NET SignalR 与LayIM配合,轻松实现网站客服聊天室(一) 整理基础数据   最近碰巧发现一款比较好的Web即时通讯前端组件,layim,百度关键字即可,我下面要做的就是基于这个前 ...