-
Notifications
You must be signed in to change notification settings - Fork 1
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
9 changed files
with
331 additions
and
1 deletion.
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
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,50 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <queue> | ||
|
||
struct idx {int z, y, x;}; | ||
|
||
int main(void) | ||
{ | ||
std::ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
|
||
int m, n, h, res = 0, non = 0; | ||
std::vector <idx> offset = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}}; | ||
std::queue <idx> que[2]; | ||
bool curQueue = false; | ||
|
||
std::cin >> n >> m >> h; | ||
int box[h][m][n]; | ||
|
||
for (int z = 0; z < h; z++) { | ||
for (int y = 0; y < m; y++) { | ||
for (int x = 0; x < n; x++) { | ||
std::cin >> box[z][y][x]; | ||
if (box[z][y][x] == 1) que[curQueue].push({z, y, x}); | ||
else if (box[z][y][x] == 0) non++; | ||
} | ||
} | ||
} | ||
|
||
while (!que[curQueue].empty() && non > 0) { | ||
while (!que[curQueue].empty()) { | ||
int z = que[curQueue].front().z, y = que[curQueue].front().y, x = que[curQueue].front().x; | ||
for (idx set : offset) { | ||
int zz = z + set.z, yy = y + set.y, xx = x + set.x; | ||
if (zz >= 0 && zz < h && yy >= 0 && yy < m && xx >= 0 && xx < n && box[zz][yy][xx] == 0) { | ||
box[zz][yy][xx] = 1, non--; | ||
que[!curQueue].push({zz, yy, xx}); | ||
} | ||
} | ||
que[curQueue].pop(); | ||
} | ||
curQueue = !curQueue; | ||
res++; | ||
} | ||
|
||
if (non > 0) std::cout << -1; | ||
else std::cout << res; | ||
|
||
return 0; | ||
} |
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
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,36 @@ | ||
#include <iostream> | ||
|
||
int main(void) | ||
{ | ||
std::ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
std::cout.tie(NULL); | ||
|
||
int n, k, bits = 0; | ||
std::string command; | ||
|
||
std::cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
std::cin >> command; | ||
if (command == "add") { | ||
std::cin >> k; | ||
bits |= (1<<k); | ||
} | ||
else if (command == "remove") { | ||
std::cin >> k; | ||
bits &= ~(1<<k); | ||
} | ||
else if (command == "check") { | ||
std::cin >> k; | ||
if (bits & (1<<k)) std::cout << "1\n"; | ||
else std::cout << "0\n"; | ||
} | ||
else if (command == "toggle") { | ||
std::cin >> k; | ||
bits ^= (1<<k); | ||
} | ||
else if (command == "all") bits = (1<<21)-1; | ||
else bits = 0; | ||
} | ||
return 0; | ||
} |
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,51 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
void cre_heap(std::vector <int> &heap, int key) { | ||
int k = heap.size(); | ||
heap.push_back(key); | ||
while (k > 1) { | ||
if (abs(heap[k/2]) > abs(heap[k]) || (abs(heap[k/2]) == abs(heap[k]) && heap[k/2] > heap[k])) { | ||
std::swap(heap[k], heap[k/2]); | ||
k /= 2; | ||
} | ||
else break; | ||
} | ||
return; | ||
} | ||
|
||
void del_heap(std::vector <int> &heap) { | ||
int k = 1; | ||
heap[1] = heap.back(), heap.pop_back(); | ||
while (k * 2 <= heap.size()) { | ||
if (k * 2 + 1 < heap.size() && (abs(heap[k*2+1]) < abs(heap[k*2]) || (abs(heap[k*2+1]) == abs(heap[k*2]) && heap[k*2+1] < heap[k*2]))) | ||
k = k*2+1; | ||
else k = k*2; | ||
|
||
if (abs(heap[k/2]) > abs(heap[k]) || (abs(heap[k/2]) == abs(heap[k]) && heap[k/2] > heap[k])) | ||
std::swap(heap[k/2], heap[k]); | ||
else break; | ||
} | ||
return; | ||
} | ||
|
||
int main(void) { | ||
std::ios_base::sync_with_stdio(false); | ||
std::cin.tie(NULL); | ||
std::cout.tie(NULL); | ||
|
||
int n, k, x; | ||
std::vector <int> abs_heap = {0}; | ||
|
||
std::cin >> n; | ||
for (int i = 0; i < n; i++) { | ||
std::cin >> x; | ||
if (abs(x) > 0) cre_heap(abs_heap, x); | ||
else if (abs_heap.size() > 1) { | ||
std::cout << abs_heap[1] << '\n'; | ||
del_heap(abs_heap); | ||
} | ||
else std::cout << 0 << '\n'; | ||
} | ||
|
||
} |
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,44 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.util.Arrays; | ||
import java.util.StringTokenizer; | ||
|
||
public class Main { | ||
|
||
static int[] A; | ||
static int[] targets; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
int N = Integer.parseInt(br.readLine()); | ||
A = new int[N]; | ||
|
||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < A.length; i++) { | ||
A[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
int M = Integer.parseInt(br.readLine()); | ||
targets = new int[M]; | ||
st = new StringTokenizer(br.readLine()); | ||
for (int i = 0; i < targets.length; i++) { | ||
targets[i] = Integer.parseInt(st.nextToken()); | ||
} | ||
|
||
Arrays.sort(A); | ||
|
||
for (int i = 0; i < targets.length; i++) { | ||
int now = targets[i]; | ||
System.out.println(binary(0, A.length - 1, now) ? 1 : 0); | ||
} | ||
} | ||
|
||
public static boolean binary(int from, int to, int n) { | ||
if (from > to) return false; | ||
int mid = (from + to) / 2; | ||
|
||
if (A[mid] == n) return true; | ||
else if (A[mid] > n) return binary(from, mid - 1, n); | ||
else return binary(mid + 1, to, n); | ||
} | ||
} |
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 @@ | ||
package μ΄μ§νμ; | ||
|
||
import java.util.Scanner; | ||
|
||
public class BOJ1300_Kλ²μ§Έμ { | ||
static int n; | ||
static int k; | ||
static int answer; | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
n = sc.nextInt(); | ||
k = sc.nextInt(); | ||
|
||
index(0, k); | ||
System.out.println(answer); | ||
} | ||
|
||
public static void index(int front, int back) { | ||
if (front > back) return; | ||
|
||
int mid = (front + back) / 2; | ||
int sum = 0; | ||
for (int i = 1; i <= n; i++) { | ||
sum += Math.min(mid / i, n); | ||
} | ||
|
||
if (sum < k) { | ||
index(mid + 1, back); | ||
} else { | ||
answer = mid; | ||
index(front, mid - 1); | ||
} | ||
} | ||
} |
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,66 @@ | ||
package μ΄μ§νμ; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.InputStreamReader; | ||
import java.io.IOException; | ||
import java.util.StringTokenizer; | ||
|
||
public class BOJ2343_κΈ°νλ μ¨ { | ||
|
||
static int N; | ||
static int M; | ||
static int[] lectures; | ||
public static void main(String[] args) throws IOException { | ||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | ||
StringTokenizer st = new StringTokenizer(br.readLine()); | ||
|
||
N = Integer.parseInt(st.nextToken()); | ||
M = Integer.parseInt(st.nextToken()); | ||
|
||
lectures = new int[N]; | ||
st = new StringTokenizer(br.readLine()); | ||
|
||
int sum = 0; | ||
int max = 0; | ||
for(int i = 0; i < N; i++) { | ||
lectures[i] = Integer.parseInt(st.nextToken()); | ||
sum += lectures[i]; | ||
max = Math.max(max, lectures[i]); | ||
} | ||
|
||
// λΈλ£¨λ μ΄μ ν¬κΈ°λ maxλΆν° sum μ¬μ΄ μΌκ²μ΄λ€. | ||
int result = minimumBlueray(max, sum); | ||
|
||
System.out.println(result); | ||
} | ||
|
||
public static int minimumBlueray(int start, int end) { | ||
if (start < end) return -1; | ||
|
||
int mid = (start + end) / 2; | ||
|
||
if (can(mid)) { | ||
int more = minimumBlueray(start, mid - 1); | ||
return more != -1 ? more : mid; | ||
} | ||
else return minimumBlueray(mid + 1, end); | ||
} | ||
|
||
public static boolean can(int blueray) { | ||
int count = M; | ||
int i = 0; | ||
int stack = blueray; | ||
while (count > 0) { | ||
while (stack - lectures[i] > 0) { | ||
if (i == N) return true; | ||
stack -= lectures[i]; | ||
i++; | ||
} | ||
|
||
stack = blueray; | ||
count--; | ||
} | ||
|
||
return false; | ||
} | ||
} |
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 @@ | ||
#include <iostream> | ||
#include <queue> | ||
|
||
using namespace std; | ||
|
||
|
||
|
||
int main(){ | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cout.tie(NULL); | ||
|
||
int n, tmp; | ||
cin >> n; | ||
|
||
priority_queue<int> q; | ||
vector<int> printq; | ||
for(int i = 0; i < n; i++){ | ||
cin >> tmp; | ||
if(tmp == 0){ | ||
if(q.empty()){ | ||
cout << 0 << "\n"; | ||
} | ||
else{ | ||
cout << q.top() << "\n"; | ||
q.pop(); | ||
} | ||
} | ||
else{ | ||
q.push(tmp); | ||
} | ||
} | ||
return 0; | ||
} |