传送门

题目问的是从出发点一直跑到终点的一条链上所有齿轮的速度和

其他的不用考虑

直接搜就好了

注意求的是绝对值之和,不是和的绝对值,所以不用考虑方向问题

注意 N<=1050 数组不要只开1007!

代码简单不注释

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
inline int read()
{
int x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=;
int n,st,ed;
int pos[N][],r[N];
double ans;
inline double f(int a,int b)
{
double x=pos[a][]-pos[b][],y=pos[a][]-pos[b][];
return sqrt(x*x+y*y);
}
int fir[N],from[N<<],to[N<<],cnt;
inline void add(int &a,int &b)
{
from[++cnt]=fir[a];
fir[a]=cnt; to[cnt]=b;
}
bool vis[N];
void dfs(int x,double res,double v)
{
if(x==ed) { ans=res; return; }
vis[x]=;
for(int i=fir[x];i;i=from[i])
{
int &u=to[i]; if(vis[u]) continue;
double vv=v*(double)r[x]/(double)r[u];
dfs(u,res+vv,vv);
}
}
int main()
{
n=read(); pos[][]=read(); pos[][]=read();
for(int i=;i<=n;i++)
{
pos[i][]=read(),pos[i][]=read(),r[i]=read();
if(pos[i][]==&&pos[i][]==) st=i;
if(pos[i][]==pos[][]&&pos[i][]==pos[][]) ed=i;
}
for(int i=;i<=n;i++)
for(int j=i+;j<=n;j++)
if(f(i,j)==(double)r[i]+(double)r[j]) add(i,j),add(j,i);
dfs(st,10000.0,10000.0);
printf("%d",(int)ans);
return ;
}

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

    P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler 题目描述 Farmer John has purchased the world's most l ...

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

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

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

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

  8. bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机【bfs】

    直接bfs即可,注意开double,还有驱动和终点的齿轮都在序列里,要把它们找出来= = #include<iostream> #include<cstdio> #includ ...

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

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1615 一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子 ...

随机推荐

  1. 【Android异常】The specified child already has a parent. You must call removeView() on the child's parent first.

    错误信息: Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must ...

  2. CheckBoxJS选中与反选得到Value

    function XuanZe(val) {    datastr = $("#hid_AID").val();    var newstr = "";    ...

  3. day35-hibernate映射 05-Hibernate的一级缓存:快照区

    SessionImpl里面有很多的Java集合,很多java集合才构成了一级缓存.一级缓存里面有一个非常特殊的区域叫做快照区.SessionImpl实现了Session接口,有很多Java集合(包括M ...

  4. 利用powerdesigner创建表模型后导出sql语句方法,以及报错 Generation aborted due to errors detected during the verification of the model.的解决办法

    今天用powerdesigner建了表模型,下面先说一下导出sql语句的步骤. 1.选项 2. 然后就报错了,下面说解决办法,很简单. 你没看错,把模型检查的√去掉就行了~~ 导出表名不带双引号的设置 ...

  5. Selenium二次封装-Java版本

    package com.yanfuchang.selenium.utils; import java.awt.AWTException; import java.awt.Robot; import j ...

  6. Struts 第一天

    请简述下Struts2 的执行流程. 首先是,启动tomcat服务器,这时候会加载web.xml,当读到filter标签时,会创建过滤器对象.struts2的核心过滤器(StrutsPrepareAn ...

  7. EXCEL数据导入数据库的另一种方式

    一.直接代码 var fileResult = openFileDialog1.ShowDialog(); if (fileResult == System.Windows.Forms.DialogR ...

  8. Entity Framework Tutorial Basics(16):Linq-to-Entities Projection Queries

    Linq-to-Entities Projection Queries: Here, you will learn how to write LINQ-to-Entities queries and ...

  9. 对 BFC 的理解

    对CSS有了解的道友们肯定都知道盒式模型这个概念,对一个元素设置CSS,首先需要知道这个元素是block还是inline类型.而BFC就是用来格式化块级盒子,同样管理inline类型的盒子还有IFC, ...

  10. Python中list常用的10个基本方法----list的灰魔法

    ########################list 的常用的10个基本方法################################## list 类 列表# 1 列表的基本格式#2 可以 ...