bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机【bfs】
直接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】的更多相关文章
- BZOJ 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
题目 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec Memory Limit: 64 MB Desc ...
- 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: ...
- 【BZOJ】1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机(模拟+bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1615 这种题..... #include <cstdio> #include <c ...
- bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...
- bzoj1615 / P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler
P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler 细节题.$O(n^{2})$的$bfs$可过. #include<iostream> ...
- 洛谷P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler
P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler 题目描述 Farmer John has purchased the world's most l ...
- BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]
1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4026 Solved: 1473[Submit] ...
- Bzoj 1598: [Usaco2008 Mar]牛跑步 dijkstra,堆,K短路,A*
1598: [Usaco2008 Mar]牛跑步 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 427 Solved: 246[Submit][St ...
- Bzoj 1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 动态规划
1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1006 Solved: ...
随机推荐
- CodeForcesGym 100517H Hentium Scheduling
Hentium Scheduling Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- CentOS下LVS DR模式负载均衡配置详解
一安装LVS准备: 1.准备4台Centos 6.2 x86_64 注:本实验关闭 SELinux和IPtables防火墙. 管理IP地址 角色 备注 192.168.1.101 LVS主调度器(Ma ...
- ORACLE ASH/AWR
(一) ASH 用户在ORACLE数据库中执行操作时,必然要创建相应的连接和会话,其中,所有当前的会话信息都保存在动态性能视图V$SESSION中,通过该视图,DBA可以查看用户实际执行的操作,或者当 ...
- DBA的40条军规
DBA操作规范 1.涉及业务上的修改/删除数据,在得到业务方.CTO的邮件批准后方可执行,执行前提前做好备份,必要时可逆. 2.所有上线需求必须走工单系统,口头通知视为无效. 3.在对大表做表结构变更 ...
- NOIP2012提高组D1T3 开车旅行
n<=100000个山,每个山有高度,从一个山到另一个山代价为高度差,有A和B两人一起开车,A每次选前进方向的次近山,B选最近,保证山高度不同且如果代价相同的山低的代价算小,每次旅行先A走,然后 ...
- sqlserver2008 存储过程使用表参数
----首先,我们定义一个表值参数类型,其实就是一个表变量 Create type dbo.tp_Demo_MultiRowsInsert as Table ( [PName] [Nvar ...
- [bzoj5379]Tree_dfs序_线段树_倍增lca
Tree bzoj-5379 题目大意:给定一棵$n$节点的树.支持:换根.把节点$u$和$v$的$lca$的子树加.询问$u$的子树和. 注释:$1\le n,q\le 3\times 10^5$. ...
- cogs——8. 备用交换机
8. 备用交换机 ★★ 输入文件:gd.in 输出文件:gd.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] n个城市之间有通讯网络,每个城市都有通讯交换机,直 ...
- Ubuntu 16.04 GNOME无法使用拼音输入法问题
说明:添加好之后重启!不然会出现输入错乱的问题. 参考: http://forum.ubuntu.org.cn/viewtopic.php?t=477765
- 详解MySQL分区表
当数据库数据量涨到一定数量时,性能就成为我们不能不关注的问题,如何优化呢? 常用的方式不外乎那么几种: 1.分表,即把一个很大的表达数据分到几个表中,这样每个表数据都不多. 优点:提高并发量,减小锁的 ...