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: ...
随机推荐
- 60. Spring Boot写后感【从零开始学Spring Boot】
从2016年4月15日到2016年7月20日经历长达3个月的时间,[从零开始学习Spring Boot]系列就要告一段落了.国内的各种资源都比较乱或者是copy 来copy去的,错了也不加以修正下,导 ...
- hihoCoder#1119 小Hi小Ho的惊天大作战:扫雷·二
原题地址 没有复杂算法,就是麻烦,写起来细节比较多,比较考验细心,一次AC好开心. 代码: #include <iostream> #include <vector> #inc ...
- [BZOJ1029] [JSOI2007]建筑抢修(贪心 + 优先队列)
传送门 把数据存在结构体中,至于怎么贪心? 肯定会有些想法,正确错误先不必说,先来试一试. 1.按照 t2 为第一关键字从小到大排,按照 t1 为第二关键字从小到大排 这个显然错,比如后面有个数的 t ...
- 【莫比乌斯反演+树状数组+分块求和】GCD Array
https://www.bnuoj.com/v3/contest_show.php?cid=9149#problem/I [题意] 给定长度为l的一个数组,初始值为0:规定了两种操作: [思路] 找到 ...
- uva10537 最短路 倒推
题意:知道了,最后需要的,那么就倒着最短路,推出去就可以了. 以最短路的方式来解决.
- Python模块:logging、
logging模块: 很多程序都有记录日志的需求,并且日志中包含的信息既有正常的程序访问日志,还可能有错误.警告等信息输出.Python的logging模块提供了标准的日志接口,你可以通过它存储各种格 ...
- 中国福利彩票,牛B,开奖和数据传输有什么关系?
昨天,由中国教育电视台直播的福利彩票“双色球”15011期开奖,在没有事先预告的情况下突然取消.晚上11点40分左右,中国福利彩票发行管理中心唯一指定网络信息发布媒体——中彩网官方微博出乎意料地在网上 ...
- 2017 CCPC 杭州 HDU6273J 区间修改(线段树&差分数组)
http://acm.hdu.edu.cn/downloads/CCPC2018-Hangzhou-ProblemSet.pdf 解析 线段树区间延迟更新 或 差分数组 两个数 统计2和3的最少的 ...
- 微信浏览器video
<style> /* 解决上下有黑边,不能全屏 */ video{object-fit: fill;} </style> <video id="videoID& ...
- 通过ambari安装hadoop集群
转载:http://www.cnblogs.com/cenyuhai/p/3295635.html 整个过程走完,问题不大,不过有一个事情要注意的是就算创建数据库的,使用localhost会报错,要使 ...