P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler
题目问的是从出发点一直跑到终点的一条链上所有齿轮的速度和
其他的不用考虑
直接搜就好了
注意求的是绝对值之和,不是和的绝对值,所以不用考虑方向问题
注意 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的更多相关文章
- 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 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: ...
- bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...
- 【BZOJ】1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机(模拟+bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1615 这种题..... #include <cstdio> #include <c ...
- bzoj1615 麻烦的干草打包机 BFS
Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...
- bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机【bfs】
直接bfs即可,注意开double,还有驱动和终点的齿轮都在序列里,要把它们找出来= = #include<iostream> #include<cstdio> #includ ...
- BZOJ_1615_[Usaco2008_Mar]_The Loathesome_Hay Baler_麻烦的干草打包机_(模拟+宽搜/深搜)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1615 一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子 ...
随机推荐
- C程序设计语言(K&R) 笔记2
(1) #include <stdio.h> main(){ int c; while((c = getchar()) != EOF){ putchar(c); } } 注意,因为 != ...
- 恢复oracle的回收站的所有的表
使用sys as sysdba 进入到sqlplus的控制界面 sqlplus / as sysdba 执行相关的命令,自动生成一个脚本文件 spool d:/a.sql select 'flashb ...
- C++——virtual
一.放在父类的函数名前面:多态 1.作用:实现多态:子类可以自定义父类中的virtual函数 #include <iostream> using namespace std; class ...
- strstr()查找函数,strchr(),strrchr(),stristr()/strpos(),strrpos()查找字符串位置
在一个较长的字符串这查找匹配的字符串或字符,其中strstr()和strchr()是完全一样的. 例: echo strstr('why always you','you'); 输出: you 如果为 ...
- mt_rand()函数、str_shuffle() 函数、join() 函数
mt_rand() 使用 Mersenne Twister 算法返回随机整数. 语法 mt_rand(min,max) 定义和用法 str_shuffle() 函数随机地打乱字符串中的所有字符. 语法 ...
- ubuntu16.04 安装caffe2
1.使用conda创建环境 conda create --name caffe2env python=3.6 ---------------------------------success----- ...
- tee 可以看见输出并将其写入到一个文件中
如下使用tee命令在屏幕上看见输出并同样写入到日志文件my.log中: [root@localhost home]# top |tee my.log tee可以保证你同时在屏幕上看到top的 ...
- Luogu 1314 [NOIP2011] 聪明的质监员
二分答案 + 前缀和. 题面中式子的意思是每一个区间$[l, r]$的贡献是这个区间内$w_i \geq W$的个数乘以这些$i$的$v_i$和. 很快发现了答案具有单调性,可以做两遍二分,分别看看小 ...
- SDUT 2142 数据结构实验之图论二:基于邻接表的广度优先搜索遍历
数据结构实验之图论二:基于邻接表的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Descript ...
- 《Effective Java》第7章 方法
第38条:检查参数的有效性 对于公有的方法,要用javadoc的@throws标签(tag)在文档中说明违反参数值限制时会抛出的异常.这样的异常通常为IllegalArgumentException, ...