• 문제 링크
15001번: Frog Leaps
It is a little known secret that frogs also like to participate in the BAPC. However, to reach Amsterdam they will need to cross lots of rivers. Fortunately, the frog is in good condition and can jump as far as he wants to go. However, jumping a distance o
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
long n = read(), p = read(), x, sum = 0;
for (; n > 1; n--, p = x) sum += (long) Math.pow((x = read()) - p, 2);
bw.write(String.valueOf(sum));
bw.flush();
}
private static long read() throws IOException {
long c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 27851 Watching Mooloo - Greedy / Java (0) | 2024.04.14 |
---|---|
[백준] 21146 Rating Problems - Greedy / Java (0) | 2024.04.13 |
[백준] 27106 Making Change - Greedy / Java (0) | 2024.04.11 |
[백준] 3578 Holes - Greedy / Java (0) | 2024.04.10 |
[백준] 5992 The Leisurely Stroll - Graph Theory / Java (0) | 2024.04.09 |
댓글