BZOJ_1615_[Usaco2008_Mar]_The Loathesome_Hay Baler_麻烦的干草打包机_(模拟+宽搜/深搜)
描述
http://www.lydsy.com/JudgeOnline/problem.php?id=1615
一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子带着转.求从主动轮到某一个轮子的路上所有轮子的转速的绝对值之和.
分析
从起点开始,枚举相接触的轮子,只要不是之前路上的(带着当前轮子转的)轮子,就继续往下走.宽搜深搜都可以.
注意:
1.%.0lf是会四舍五入的!所以要强制转化成int.
宽搜:
#include <bits/stdc++.h>
using namespace std; const int maxn=+;
const double eps=1e-;
struct node{ double x,y,r; }a[maxn];
int n,s,t;
int q[maxn];
bool vis[maxn];
double xt,yt;
double s_[maxn],ans[maxn];
inline bool c(node a,node b){ return fabs((sqrt(pow(a.x-b.x,)+pow(a.y-b.y,))-a.r-b.r))<eps; }
int main(){
scanf("%d%lf%lf",&n,&xt,&yt);
for(int i=;i<=n;i++){
scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
if(a[i].x==0.0&&a[i].y==0.0) s=i;
else if(a[i].x==xt&&a[i].y==yt) t=i;
}
int front=,tail=;
q[tail++]=s; vis[s]=true; s_[s]=ans[s]=;
while(front!=tail){
int u=q[front++];
if(u==t){ printf("%d\n",(int)ans[u]); return ; }
for(int v=;v<=n;v++)if(!vis[v]&&c(a[u],a[v])){
s_[v]=-s_[u]*a[u].r/a[v].r;
ans[v]+=fabs(s_[v])+ans[u];
vis[v]=true;
q[tail++]=v;
}
}
return ;
}
深搜:
#include <bits/stdc++.h>
using namespace std; const int maxn=+;
const double eps=1e-;
struct node{ double x,y,r; }a[maxn];
int n,s,t;
int q[maxn];
double xt,yt;
bool vis[maxn];
inline bool c(node a,node b){ return fabs(sqrt(pow(a.x-b.x,)+pow(a.y-b.y,))-a.r-b.r)<eps; }
double dfs(int u,double sp,double ans){
if(u==t) return ans;
for(int v=;v<=n;v++)if(!vis[v]&&c(a[u],a[v])){
vis[v]=true;
double S=-sp*a[u].r/a[v].r;
return dfs(v,S,ans+fabs(S));
}
}
int main(){
scanf("%d%lf%lf",&n,&xt,&yt);
for(int i=;i<=n;i++){
scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
if(a[i].x==0.0&&a[i].y==0.0) s=i;
else if(a[i].x==xt&&a[i].y==yt) t=i;
}
vis[s]=true;
printf("%d\n",(int)dfs(s,,));
return ;
}
BZOJ_1615_[Usaco2008_Mar]_The Loathesome_Hay Baler_麻烦的干草打包机_(模拟+宽搜/深搜)的更多相关文章
- 【BZOJ】1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机(模拟+bfs)
http://www.lydsy.com/JudgeOnline/problem.php?id=1615 这种题..... #include <cstdio> #include <c ...
- 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 / 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 ...
- bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机
Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...
- bzoj1615 麻烦的干草打包机 BFS
Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互 ...
- P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler
传送门 题目问的是从出发点一直跑到终点的一条链上所有齿轮的速度和 其他的不用考虑 直接搜就好了 注意求的是绝对值之和,不是和的绝对值,所以不用考虑方向问题 注意 N<=1050 数组不要只开10 ...
- bzoj 1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机【bfs】
直接bfs即可,注意开double,还有驱动和终点的齿轮都在序列里,要把它们找出来= = #include<iostream> #include<cstdio> #includ ...
随机推荐
- How to: Declare encoding UTF-8 in python
References: http://stackoverflow.com/questions/12238307/declaring-encoding-in-python http://stackove ...
- python isinstance 判断各种类型的小细节
1. 基本语法 isinstance(object, classinfo) Return true if the object argument is an instance of the class ...
- 【转载】C#后台声明式验证,远离if验证
ViewModel public class ViewModel { [Required(ErrorMessage="标题不能为空")] public string Title { ...
- jQuery入门[1]-构造函数【转载】
最近看了一些jquery的进阶教程,感觉很不错,与大家分享下! jQuery——构造函数 ◦体积小(v1.2.3 15kb)◦丰富的DOM选择器(CSS1-3 + XPath) ◦跨浏览器(IE6,F ...
- C#使用oledb方式将excel数据导入到datagridview后数据被截断为 255 个字符
问题描述:在使用oledb方式将excel数据导入到datagridview中,在datagridview单元格中的数据没有显示全,似乎只截取了数据源中的一段 解决方案:1.关于该问题,微软官方答案: ...
- LESS语法备忘
变量 很容易理解: @nice-blue: #5B83AD; @light-blue: @nice-blue + #111; #header { color: @light-blue; } 输出: # ...
- FireMonkey消息机制
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes, FMX.Forms, FMX.Plat ...
- Hadoop常见的45个问题解答
(大讲台:国内首个it在线教育混合式自适应学习) 1.Hadoop集群可以运行的3个模式 单机(本地)模式 伪分布式模式 全分布式模式 2. 单机(本地)模式中的注意点? 在单机模式(standal ...
- Xcode 7.3.1的模拟器路径
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Library/Core ...
- 如何学习C++[转]
关于学C++, 我向你推荐一些书(当然能够结合课内项目实践更好) 1.The C++ Programming Language(Bjarne Stroustrup)2. Inside The C++ ...