Study/알고리즘 문제풀이
백준 1592. 영식이와 친구들 :: 돼지개발자
돼지개발자
2019. 1. 16. 15:55
출저 : https://www.acmicpc.net/problem/1592
"시뮬레이션"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import java.util.Scanner; public class Main { static int n,m,l; static int[] map; static int cur, next; static int res; static Scanner sc = new Scanner(System.in); public static void main(String[] args) { n = sc.nextInt(); m = sc.nextInt(); l = sc.nextInt(); map = new int[n]; while(true) { if(++map[cur] == m) break; if(map[cur] % 2 == 0) { next = cur + l >= n ? l - (n - cur) : cur + l; } else { next = cur - l < 0 ? n - (l - cur) : cur - l; } cur = next; res++; } System.out.println(res); } } | cs |