-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
336 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* 수 정렬하기 3 | ||
* https://www.acmicpc.net/problem/10989 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException{ | ||
int n = Integer.parseInt(br.readLine()); | ||
int[] data = new int[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
data[i] = Integer.parseInt(br.readLine()); | ||
} | ||
Arrays.sort(data); | ||
|
||
for (int i = 0; i < n; i++) { | ||
sb.append(data[i]).append("\n"); | ||
} | ||
System.out.println(sb.toString().trim()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
static StringBuilder sb = new StringBuilder(); | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
|
||
/** | ||
* 이항 계수 1 | ||
* https://www.acmicpc.net/problem/11050 | ||
*/ | ||
public static void main(String[] args) throws IOException{ | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int k = Integer.parseInt(st.nextToken()); | ||
int[] factorial = new int[n + 1]; | ||
|
||
factorial[0] = 1; | ||
factorial[1] = 1; | ||
for (int i = 2; i <= n; i++) { | ||
factorial[i] = factorial[i - 1] * i; | ||
} | ||
|
||
System.out.println(factorial[n] / (factorial[n - k] * factorial[k])); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.util.stream.*; | ||
|
||
/** | ||
* 좌표 정렬하기1 | ||
* https://www.acmicpc.net/problem/11650 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException{ | ||
int n = Integer.parseInt(br.readLine()); | ||
Coordinate[] coordinates = new Coordinate[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
coordinates[i] = new Coordinate( | ||
Integer.parseInt(st.nextToken()), | ||
Integer.parseInt(st.nextToken()) | ||
); | ||
} | ||
|
||
String answer = Arrays.stream(coordinates) | ||
.sorted(Comparator.comparingInt(Coordinate::getX) | ||
.thenComparing( | ||
Comparator.comparing(Coordinate::getY))) | ||
.map(String::valueOf) | ||
.collect(Collectors.joining("\n")); | ||
|
||
System.out.println(answer); | ||
} | ||
|
||
|
||
static class Coordinate{ | ||
int x; | ||
int y; | ||
|
||
public Coordinate(int x, int y){ | ||
this.y = y; | ||
this.x = x; | ||
} | ||
|
||
public int getY(){ | ||
return y; | ||
} | ||
|
||
public int getX(){ | ||
return x; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return x + " " + y; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.util.stream.*; | ||
|
||
/** | ||
* 좌표 정렬하기2 | ||
* https://www.acmicpc.net/problem/11651 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException{ | ||
int n = Integer.parseInt(br.readLine()); | ||
Coordinate[] coordinates = new Coordinate[n]; | ||
|
||
for (int i = 0; i < n; i++) { | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
coordinates[i] = new Coordinate( | ||
Integer.parseInt(st.nextToken()), | ||
Integer.parseInt(st.nextToken()) | ||
); | ||
} | ||
|
||
String answer = Arrays.stream(coordinates) | ||
.sorted(Comparator.comparingInt(Coordinate::getY) | ||
.thenComparing( | ||
Comparator.comparing(Coordinate::getX))) | ||
.map(String::valueOf) | ||
.collect(Collectors.joining("\n")); | ||
|
||
System.out.println(answer); | ||
} | ||
|
||
|
||
static class Coordinate{ | ||
int x; | ||
int y; | ||
|
||
public Coordinate(int x, int y){ | ||
this.y = y; | ||
this.x = x; | ||
} | ||
|
||
public int getY(){ | ||
return y; | ||
} | ||
|
||
public int getX(){ | ||
return x; | ||
} | ||
|
||
@Override | ||
public String toString(){ | ||
return x + " " + y; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.util.*; | ||
import java.io.*; | ||
import java.util.stream.*; | ||
|
||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder();; | ||
|
||
public static void main(String[] args) throws IOException{ | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
int n = Integer.parseInt(st.nextToken()); | ||
int k = Integer.parseInt(st.nextToken()); | ||
|
||
List<Integer> q = IntStream.range(1, n + 1) | ||
.boxed() | ||
.collect(Collectors.toList()); | ||
List<Integer> answer = new ArrayList<>(); | ||
|
||
int idx = 0; | ||
while (q.size() > 1){ | ||
idx = (idx + (k - 1)) % q.size(); | ||
|
||
answer.add(q.remove(idx)); | ||
} | ||
answer.add(q.remove(0)); | ||
|
||
System.out.println( | ||
answer.stream() | ||
.map(String::valueOf) | ||
.collect(Collectors.joining(", ", "<", ">")) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import java.io.*; | ||
|
||
/** | ||
* Hashing | ||
* https://www.acmicpc.net/problem/15829 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
static long MOD = 1234567891; | ||
|
||
public static void main(String[] args) throws IOException{ | ||
int n = Integer.parseInt(br.readLine()); | ||
|
||
char[] plain = br.readLine().toCharArray(); | ||
long res = 0; | ||
long pow = 1; | ||
|
||
for (int i = 0; i < n; i++) { | ||
res += ((plain[i] - 'a' + 1) * pow); | ||
pow = (pow * 31) % MOD; | ||
} | ||
|
||
System.out.println(res % MOD); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import java.util.*; | ||
import java.io.*; | ||
|
||
/** | ||
* 마인크래프트 | ||
* https://www.acmicpc.net/problem/18111 | ||
*/ | ||
public class Main { | ||
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
static StringBuilder sb = new StringBuilder(); | ||
|
||
public static void main(String[] args) throws IOException{ | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
Minecraft.n = Integer.parseInt(st.nextToken()); | ||
Minecraft.m = Integer.parseInt(st.nextToken()); | ||
Minecraft.baseLeft = Integer.parseInt(st.nextToken()); | ||
Minecraft.map = new int[Minecraft.n][Minecraft.m]; | ||
Minecraft answer = null; | ||
int maxHeight = Integer.MIN_VALUE; | ||
int minHeight = Integer.MAX_VALUE; | ||
|
||
for (int i = 0; i < Minecraft.n; i++) { | ||
st = new StringTokenizer(br.readLine()); | ||
for (int j = 0; j < Minecraft.m; j++) { | ||
Minecraft.map[i][j] = Integer.parseInt(st.nextToken()); | ||
maxHeight = Math.max(maxHeight, Minecraft.map[i][j]); | ||
minHeight = Math.min(minHeight, Minecraft.map[i][j]); | ||
} | ||
} | ||
|
||
for (int i = minHeight; i <= maxHeight; i++) { | ||
Minecraft minecraft = new Minecraft(i); | ||
minecraft.flat(); | ||
if(Objects.isNull(answer) || answer.compareTo(minecraft) > 0){ | ||
answer = minecraft; | ||
} | ||
} | ||
|
||
System.out.println(answer); | ||
} | ||
|
||
static class Minecraft implements Comparable<Minecraft>{ | ||
static int n; | ||
static int m; | ||
static int[][] map; | ||
static int baseLeft; | ||
int left; | ||
int time; | ||
int height = 0; | ||
|
||
public Minecraft(int height) { | ||
this.height = height; | ||
left = Minecraft.baseLeft; | ||
this.time = 0; | ||
} | ||
|
||
void flat(){ | ||
actionFlat(height, (i, j, h) -> { | ||
int gap = map[i][j] - h; | ||
time += (gap * 2); | ||
left += gap; | ||
}, (i, j, h) -> { | ||
int gap = h - map[i][j]; | ||
time += gap; | ||
left -= gap; | ||
}); | ||
|
||
if(left < 0) time = Integer.MAX_VALUE; | ||
} | ||
|
||
private void actionFlat(int height, TriConsumer<Integer, Integer, Integer> higher, | ||
TriConsumer<Integer, Integer, Integer> lower) { | ||
for (int i = 0; i < n; i++) { | ||
for (int j = 0; j < m; j++) { | ||
if(map[i][j] > height) higher.apply(i, j, height); | ||
else lower.apply(i, j, height); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public int compareTo(Minecraft o) { | ||
if(Integer.compare(this.time, o.time) == 0){ | ||
return Integer.compare(this.height, o.height); | ||
} else { | ||
return Integer.compare(this.time, o.time); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return time + " " + height; | ||
} | ||
} | ||
|
||
@FunctionalInterface | ||
interface TriConsumer<T, U, V>{ | ||
void apply(T t, U u, V v); | ||
} | ||
} |