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 ...
随机推荐
- eclipse导入包的快捷键
在Eclipse里,写一个没有导入相应包的类名(这个类名已经完全写全,比如LayoutManager), 可以用ctrl+shift+M/Ctrl+Shift+o/Ctrl+1导入相应的包. 其中Ct ...
- Windows 7 Shortcuts (完整兼具分类有序,想我所想,赞!)
Original Link: http://www.shortcutworld.com/en/win/Windows_7.html Table of Contents: Managing 'Windo ...
- WebClient以POST方式发送Web请求
本例使用WebClient以POST方式发送Web请求并下载一个文件,难点是postData的构造,发送Web请求时有的网站要求可能要求 Cookies前后一致.其中application/x-www ...
- 对WebClient扩展自动解压缩页面
WebClient下载压缩网页时出现的全是乱码,可通过扩展来解决这个问题. public class MyWebClient : WebClient { protected override WebR ...
- H5发展简介
HTML4.01 超文本标记语言,1999年12月24日由W3C组织发布. XHTML 扩展的超文本标记语言(eXtensible Hyper Text Markup Language),和HTML4 ...
- Spring 官方下载地址(非Maven)
现在spring的官网停止了使用zip包下载,只能使用maven,非常的不方便,分享如下网址可以使用zip包下载,是不是方便多了!~ 下载列表如下: spring-framework-3.2.8.RE ...
- windows 系统下,小数据量Oracle用户物理备份
环境:windows Server 2003 oracle 10g,系统间备份 目标系统创建共享文件,原系统挂载共享目录 写批处理脚本,用任务计划定时调用 Rem * 由于系统实时性要求不是很高,数据 ...
- hdu 5654 xiaoxin and his watermelon candy 树状数组维护区间唯一元组
题目链接 题意:序列长度为n(1<= n <= 200,000)的序列,有Q(<=200,000)次区间查询,问区间[l,r]中有多少个不同的连续递增的三元组. 思路:连续三元组-& ...
- FontDialog组件设置字体
1.设置字体 private void button3_Click(object sender, EventArgs e) { this.fontDialog1.ShowDialog(); this. ...
- 使用Memcached、Spring AOP构建数据库前端缓存框架
数据库访问可能是很多网站的瓶颈.动不动就连接池耗尽.内存溢出等.前面已经讲到如果我们的网站是一个分布式的大型站点,那么使用 memcached实现数据库的前端缓存是个很不错的选择:但如果网站本身足够小 ...