mirror of
https://github.com/Xevion/contest.git
synced 2025-12-17 20:11:32 -06:00
feb 2015 problem 1 / 3 / 4
This commit is contained in:
11
uil/aplus-february-2015/3/Climb.MD
Normal file
11
uil/aplus-february-2015/3/Climb.MD
Normal file
@@ -0,0 +1,11 @@
|
||||
# Climb
|
||||
|
||||
Run my solution on **[repl.it](https://repl.it/@Xevion/A-Computer-Science-February-2015-Climb)!**
|
||||
|
||||
This problem is very basic indeed, a simple while loop with two if statements is all one needs. Perhaps this could be made into an equation, but it's best if your pursue the simpler routes.
|
||||
|
||||
I added a `if statement` inside the `while loop` to make sure it didn't decrement following the ant reaching the summit of the hill, which would report an extra "climb" operation and a slightly higher distance traversed.
|
||||
|
||||
Taking your time on these Competition problems is not what is asked, as these are timed in real competition scenarios, so one should aim to simply solve the test cases, not solve world hunger while you're at it.
|
||||
|
||||
This problem is one of those that should be attempted first, to attain easy points immediately before starting difficult to solve problems.
|
||||
29
uil/aplus-february-2015/3/Climb.java
Normal file
29
uil/aplus-february-2015/3/Climb.java
Normal file
@@ -0,0 +1,29 @@
|
||||
import static java.lang.System.out;
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Scanner s = new Scanner(new File("climb.dat"));
|
||||
for(int i = s.nextInt(); i > 0; i--) {
|
||||
int up = s.nextInt();
|
||||
int down = s.nextInt();
|
||||
int hole = -1 * s.nextInt();
|
||||
|
||||
int attempts = 0;
|
||||
int traverse = 0;
|
||||
while(hole < 0) {
|
||||
attempts++;
|
||||
hole += up;
|
||||
traverse += up;
|
||||
if(hole < 0) {
|
||||
hole -= down;
|
||||
traverse += down;
|
||||
}
|
||||
}
|
||||
|
||||
out.println(String.format("%s %s", attempts, traverse));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user