bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

感觉自己像个智障

直接bfs

然而读入没判负号查了半小时。。

 1 #include<cstdio>
 2 #include<cctype>
 3 #include<cmath>
 4 #include<cstring>
 5 #include<algorithm>
 6 using namespace std;
 7 #define maxn 1100
 8 #define eps 1e-8
 9 int n,tx,ty;
10 int st,ed;
11 int x[maxn],y[maxn],r[maxn];
12 double v[maxn],ans;
13 bool vis[maxn];
14 int q[maxn*5];
15 int fa[maxn];
16 inline int read(){
17     int x=0,f=1;char ch=getchar();
18     while (!isdigit(ch)) {
19         if (ch==‘-‘) f=-1;
20         ch=getchar();
21     }
22     while (isdigit(ch)) {
23         x=x*10+ch-‘0‘;
24         ch=getchar();
25     }
26     return x*f;
27 }
28 inline bool ok(int i,int j){
29     double dis=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
30     double d2=r[i]+r[j];
31     if (dis==d2*d2) return 1;
32     else return 0;
33 }
34 inline void bfs(){
35     int head=0,tail=1;
36     q[head]=st;v[st]=10000;vis[st]=1;
37     while (head<tail){
38         int now=q[head];head++;
39         for (int i=1;i<=n;i++){
40             if (!vis[i]&&ok(now,i)){
41                 vis[i]=1,q[tail++]=i;
42                 fa[i]=now;
43                 v[i]=v[now]/r[i]*r[now];
44                 if (i==ed) return;
45              }
46         }
47
48     }
49 }
50 int main(){
51     n=read(),tx=read(),ty=read();
52     for (int i=1;i<=n;i++){
53         x[i]=read(),y[i]=read(),r[i]=read();
54         if (x[i]==0&&y[i]==0) st=i;
55         if (x[i]==tx&&y[i]==ty) ed=i;
56     }
57     memset(v,0,sizeof(v));
58     memset(vis,0,sizeof(vis));
59     memset(q,0,sizeof(q));
60     memset(fa,0,sizeof(fa));
61     bfs();
62     ans=0;
63     for (int i=ed;i;i=fa[i])
64       ans+=v[i];
65     printf("%d\n",(int)ans);
66     return 0;
67 }

时间: 2024-08-25 09:48:53

bzoj1615 [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机的相关文章

1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机

1615: [Usaco2008 Mar]The Loathesome Hay Baler麻烦的干草打包机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 574  Solved: 226[Submit][Status] Description Farmer John新买的干草打包机的内部结构大概算世界上最混乱的了,它不象普通的机器一样有明确的内部传动装置,而是,N (2 <= N <= 1050)个齿轮互相作用,每个齿轮都可能驱动着多个齿轮. FJ

洛谷P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler

P2903 [USACO08MAR]麻烦的干草打包机The Loathesome Hay Baler 题目描述 Farmer John has purchased the world's most loathesome hay baler. Instead of having a drive-roller that drives maybe an idler roller that drives the power take-off for the baler, it has N rollers

BZOJ_1615_[Usaco2008_Mar]_The Loathesome_Hay Baler_麻烦的干草打包机_(模拟+宽搜/深搜)

描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1615 一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子带着转.求从主动轮到某一个轮子的路上所有轮子的转速的绝对值之和. 分析 从起点开始,枚举相接触的轮子,只要不是之前路上的(带着当前轮子转的)轮子,就继续往下走.宽搜深搜都可以. 注意: 1.%.0lf是会四舍五入的!所以要强制转化成int. 宽搜: 1 #include <bits/stdc++.h

1597: [Usaco2008 Mar]土地购买 [ dp+斜率优化 ] 未完

传送门 1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1979  Solved: 705[Submit][Status][Discuss] Description 农夫John准备扩大他的农场,他正在考虑N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000,000; 1 <= 长 <= 1,000,000). 每

[BZOJ1617][Usaco2008 Mar]River Crossing渡河问题

1617: [Usaco2008 Mar]River Crossing渡河问题 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 1102  Solved: 801 [Submit][Status][Discuss] Description Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏. 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木筏上.在这个基础上,木筏上的奶牛数

【Usaco2008 Mar】土地购买

[题目描述] 农夫John准备扩大他的农场,他正在考虑N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000,000; 1 <= 长 <= 1,000,000). 每块土地的价格是它的面积,但FJ可以同时购买多快土地. 这些土地的价格是它们最大的长乘以它们最大的宽, 但是土地的长宽不能交换. 如果FJ买一块3x5的地和一块5x3的地,则他需要付5x5=25. FJ希望买下所有的土地,但是他发现分组来买这些土地可以节

[BZOJ1579][Usaco2008 Mar]土地购买

1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5094  Solved: 1887[Submit][Status][Discuss] Description 农夫John准备扩大他的农场,他正在考虑N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000,000; 1 <= 长 <= 1,000,000). 每块土地

1682: [Usaco2005 Mar]Out of Hay 干草危机

1682: [Usaco2005 Mar]Out of Hay 干草危机 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 391  Solved: 258[Submit][Status] Description The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms

bzoj 1597: [Usaco2008 Mar]土地购买 2011-12-27

1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 697  Solved: 244[Submit][Status][Discuss] Description 农夫John准备扩大他的农场,他正在考虑N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000,000; 1 <= 长 <= 1,000,000). 每块土地的价