@@ -5,8 +5,6 @@ title: Hoofball
5
5
author : Ryan Chou, Ben Dodge, Arpan Banerjee
6
6
---
7
7
8
- [ Official Analysis (C++)] ( http://www.usaco.org/current/data/sol_hoofball_bronze_feb18.html )
9
-
10
8
## Video Solution
11
9
By Arpan Banerjee
12
10
@@ -61,7 +59,6 @@ int main(){
61
59
```
62
60
63
61
</CPPSection>
64
-
65
62
<JavaSection>
66
63
67
64
```java
@@ -126,11 +123,27 @@ class Main {
126
123
}
127
124
}
128
125
` ` `
129
- </JavaSection>
130
126
127
+ </JavaSection>
131
128
</LanguageSection>
132
129
</Spoiler>
133
130
131
+ <Spoiler title="Hint 1">
132
+
133
+ Play with the sample input, and draw out other cases.
134
+
135
+ </Spoiler>
136
+
137
+ <Spoiler title="Hint 2">
138
+
139
+ When will a ball get stuck in an infinite loop?
140
+
141
+ </Spoiler>
142
+
143
+ <Spoiler title="Solution">
144
+
145
+ [Official Analysis (C++)](http://www.usaco.org/current/data/sol_hoofball_bronze_feb18.html)
146
+
134
147
## Explanation
135
148
136
149
First, let's realize that Farmer John will need another ball in one of two cases:
@@ -141,6 +154,7 @@ So, each time this occurs we can count it and return this total count as our ans
141
154
We can do this first by finding which cow, if any, every cow passes the ball to.
142
155
143
156
## Implementation
157
+
144
158
**Time Complexity:** $\m athcal{O}(N^2)$
145
159
146
160
<LanguageSection>
@@ -195,6 +209,7 @@ for i in range(n):
195
209
196
210
print (ans )
197
211
` ` `
212
+
198
213
</PySection>
199
214
<CPPSection>
200
215
@@ -262,7 +277,6 @@ int main() {
262
277
` ` `
263
278
264
279
</CPPSection>
265
-
266
280
<JavaSection>
267
281
268
282
` ` ` java
@@ -336,9 +350,11 @@ public class Hoofball {
336
350
io .println (ballsNeeded );
337
351
io .close ();
338
352
}
339
- // CodeSnip{Kattio}
353
+
354
+ // CodeSnip{Kattio}
340
355
}
341
-
342
- ` ` `
356
+ ` ` `
357
+
343
358
</JavaSection>
344
359
</LanguageSection>
360
+ </Spoiler>
0 commit comments