목록Algorithm (127)
main
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int honeyHouse = 1; int d = 6; int d_cnt = 1; while (true) { if (honeyHouse >= N) break; honeyHouse += d * d_cnt; d_cnt++; } System.out.println(d_cnt); sc.close(); } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int A = sc.nextInt(); int B = sc.nextInt(); int C = sc.nextInt(); if (B >= C) { System.out.println(-1); } else if ((double) A / (C - B) + 1 > 1) { System.out.println(A / (C - B) + 1); } sc.close(); } }
* 브루트포스 알고리즘; 완전탐색 * 등차수열 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); sc.close(); int[] arr = new int[num + 1]; arr[0] = -1; for (int i = 1; i < arr.length; i++) { arr[i] = i; } for (int i = 1; i < arr.length; i++) { int a = i; if (a / 100 == 0) { continue; // 한 자릿수, 두 자릿수 는 다 한수 } // 등차수열 공차 ..
* 브루트포스 알고리즘; 완전탐색 public class Main { public static void main(String[] args) { int[] selfNums = new int[10001]; selfNums[0] = -1; for (int i = 1; i
* 그리디 알고리즘 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long num = sc.nextLong(); long answer = 0; long i = 1; while (true) { answer += i; if (answer + (i + 1) > num) { System.out.println(i); break; } i++; } sc.close(); } }