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 一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子 ...
随机推荐
- import gevent 协程 import greenlet
- css知多少(3)——样式来源与层叠规则(转)
css知多少(3)——样式来源与层叠规则 上一节<css知多少(2)——学习css的思路>有几个人留言表示思路很好.继续期待,而且收到了9个赞,我还是比较欣慰的.没看过的朋友建议先去看 ...
- WINFORM 无边框窗体 阴影与移动
//窗体移动API[DllImport("user32.dll")]public static extern bool ReleaseCapture();[DllImport(&q ...
- Executor线程池
Executor线程池框架: 使用线程池的优点: 1.重用存在的线程 2.减少对象创建.消亡的开销 3.性能佳 4.可有效控制最大并发线程数,提高系统资源的使用率 5.避免过多资源竞争,避免堵塞 6. ...
- oracle错误汇总解决
1.ORA-12514 http://blog.sina.com.cn/s/blog_5007d1b10100oqo8.html
- R: 关于文件 文件夹的处理:file.show() dir.create().....
文件管理主要函数: setwd( ):设定R软件当前工作目录.getwd( ):查看R软件当前工作目录.list.files( ): 查看当前目录下文件.file.show( ): 显示文件.file ...
- 浅谈assert()函数的用法
#include<stdio.h> #include<assert.h> char * Strcpy(char *dst,const char *src) { assert(d ...
- java 的exception throw try catch
import java.util.*; public class MyException extends Exception { private static final Exception Exce ...
- 洛谷 P1879 [USACO06NOV]玉米田Corn Fields
题目描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ...
- AB二进制
Description 若将一个正整数化为二进制数,在此二进制数中,我们将数字1的个数多于数字0的个数的这类二进制数称为A类数,否则就称其为B类数. 例如: (13)10=(1101)2 ...