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

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1505;
int n,sx,sy,s,t,q[N],fr[N];
bool v[N];
double ans,dis[N];
struct qwe
{
int x,y,r;
}a[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
inline int jl(int x,int y)
{
return (a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y);
}
int main()
{
n=read(),sx=read(),sy=read();
for(int i=1;i<=n;i++)
a[i].x=read(),a[i].y=read(),a[i].r=read();
for(int i=1;i<=n;i++)
{
if(!a[i].x&&!a[i].y)
s=i;
if(a[i].x==sx&&a[i].y==sy)
t=i;
}
queue<int>q;
q.push(s),dis[s]=10000,v[s]=1;
while(!q.empty())
{
int u=q.front();
q.pop();
for(int i=1;i<=n;i++)
if(!v[i]&&(a[u].r+a[i].r)*(a[u].r+a[i].r)==jl(u,i))
{
fr[i]=u;
v[i]=1,q.push(i);
dis[i]=dis[u]*a[u].r/a[i].r;
if(i==t)
break;
}
}
for(int i=t;i;i=fr[i])
ans+=dis[i];
printf("%d\n",(int)ans);
return 0;
}

bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机【bfs】的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  8. Bzoj 1598: [Usaco2008 Mar]牛跑步 dijkstra,堆,K短路,A*

    1598: [Usaco2008 Mar]牛跑步 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 427  Solved: 246[Submit][St ...

  9. Bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 动态规划

    1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1006  Solved: ...

随机推荐

  1. 【02】AJAX XMLHttpRequest对象

    AJAX XMLHttpRequest对象   XMLHttpRequest 对象用于与服务器交换数据,能够在不重新加载整个网页(刷新)的情况下,对网页进行部分更新. XMLHttpRequest 对 ...

  2. swagger & api & swagger ui

    swagger & api swagger ui # run server $ swagger project start api-app # call api $ curl http://1 ...

  3. CentOS 6.4 下用ntfs-3g挂载Windows NTFS分区

    默认情况下,CentOS 6.4不支持Widows NTFS硬盘分区读写,要想把NTFS格式的磁盘挂载到CentOS 6.4下面 需要安装第三方的插件ntfs-3g,这里我们采用编译安装插件. 1.安 ...

  4. Codeforces 645A Amity Assessment【八数码】

    题目链接: http://codeforces.com/problemset/problem/645/A 题意: 2*2的八数码问题 分析: 这题n为2,不需要搜索,直接判断字母排列顺序就好了. 注意 ...

  5. lines-HDU5124(区间处理 +离散化)

    Problem Description John has several lines. The lines are covered on the X axis. Let A is a point wh ...

  6. P1996||T1282 约瑟夫问题 洛谷||codevs

    https://www.luogu.org/problem/show?pid=1996||http://codevs.cn/problem/1282/ 题目背景 约瑟夫是一个无聊的人!!! 题目描述 ...

  7. codevs 3498 小木棍

    3498 小木棍  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 乔治有一些同样长的小木棍,他把这些木棍随意 ...

  8. Ubuntu 16.04安装GTX960闭源驱动

    GTX960的闭源要Nvidia 346版才行,闭源驱动能很大提升显卡的性能,例如双显示输出等,缺点是不开源. 有以下方式来安装: 1.命令行: sudo add-apt-repository -y ...

  9. tsdb import 相关

    今天一直在做opentsdb 大量导入数据的工作. 中间遇到了一些值得记录的问题, 这里随手记一下 明天好好整理 1. 多进程logger python的logging模块不支持多进程,但我们可以用s ...

  10. zabbix学习系列之QQ消息报警

    安装依赖包 环境 Zabbix: 3.2 OS:Centos 安装依赖包 yum install lrzsz chrony gcc gcc-c++ git openssl-devel perl-Ext ...