-
Notifications
You must be signed in to change notification settings - Fork 0
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
13 changed files
with
403 additions
and
92 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
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,71 @@ | ||
#include<iostream> | ||
#include<queue> | ||
using namespace std; | ||
int tom[101][101][101]; //ν λ§ν μ μνλ₯Ό μ μ₯νκΈ°μν λ°°μ΄ | ||
int col, row, height; | ||
int x[6] = { 0,0,-1,1,0,0 }; | ||
int y[6] = { -1,1,0,0,0,0 }; | ||
int z[6] = { 0,0,0,0,1,-1 }; | ||
struct tomato { //ν λ§ν μ μ’νλ₯Ό μ μ₯νκΈ°μν ꡬ쑰체 | ||
int x1; //μ΄ | ||
int y1; //ν | ||
int z1; //λμ΄ | ||
tomato(int _x1, int _y1, int _z1) { | ||
x1 = _x1; y1 = _y1; z1 = _z1; | ||
|
||
} | ||
}; | ||
queue<tomato>q; | ||
void bfs() { | ||
while (!q.empty()) { | ||
tomato t = q.front(); | ||
q.pop(); | ||
for (int i = 0; i < 6; i++) { //νμλ²μ(μ,ν,μ’,μ°,μ,μλ) | ||
int _x = t.x1 + x[i]; | ||
int _y = t.y1 + y[i]; | ||
int _z = t.z1 + z[i]; | ||
if (_x < col && _x >= 0 && _y < row && _y >= 0 && _z < height && _z >= 0 && tom[_z][_y][_x] == 0) { | ||
tom[_z][_y][_x] = tom[t.z1][t.y1][t.x1] + 1; | ||
q.push(tomato(_x, _y, _z)); | ||
|
||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cin >> col >> row >> height; | ||
|
||
for (int i = 0; i < height; i++) { | ||
for (int j = 0; j < row; j++) { | ||
for (int k = 0; k < col; k++) { | ||
cin >> tom[i][j][k]; | ||
if (tom[i][j][k] == 1) //μ΅μν λ§ν κ° λ€μ΄μμΌλ©΄ | ||
q.push(tomato(k, j, i)); //νμμμμ μμν΄ κ·Έ μ’νλ₯Ό νμ λ£λλ€. | ||
} | ||
} | ||
} | ||
|
||
bfs(); // | ||
int sum = 0; | ||
for (int i = 0; i < height; i++) { | ||
for (int j = 0; j < row; j++) { | ||
for (int k = 0; k < col; k++) { | ||
if (tom[i][j][k] == 0) //bfsν μμ΅μν λ§ν κ° μλ€λ©΄ λͺ¨λμ΅μ§λͺ»νλ μν©μ΄λ―λ‘ -1μ μΆλ ₯ | ||
{ | ||
cout << -1; | ||
return 0; | ||
} | ||
if (sum < tom[i][j][k]) sum = tom[i][j][k]; //bfs ν κ±Έλ¦°μκ°μ μ°ΎκΈ°μν΄ tomλ°°μ΄μ μ΅λκ°μ μ°Ύμ sumμ μ μ₯νλκ³Όμ | ||
|
||
} | ||
} | ||
} | ||
|
||
sum == 1 ? cout << 0 : cout << sum - 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,55 @@ | ||
#include<iostream> | ||
using namespace std; | ||
char color[100][100]; //μ μμΈμ΄ 보λ κ·Έλ¦Ό | ||
char color2[100][100]; //μ λ‘μμ½μ΄ 보λ κ·Έλ¦Ό | ||
bool visited[100][100]; //μ μμΈ κ·Έλ¦Όμ λ°©λ¬Έμ¬λΆ | ||
bool visited2[100][100]; //μ λ‘μμ½ κ·Έλ¦Όμ λ°©λ¬Έμ¬λΆ | ||
string line; // νμ€ μ λ ₯μ λ°κΈ°μν μ€νΈλ§ | ||
int siz; //κ·Έλ¦Όμ ν λ³μ κΈΈμ΄ | ||
int coun = 0; //μ μμΈμ΄ κ·Έλ¦Όμλ΄€μλ ꡬμμκ°μ | ||
int coun2 = 0; //μ λ‘μμ½μ΄ λ΄€μλ ꡬμμκ°μ | ||
int x[4]={0,0,-1,1}; //μνμ’μ° νμμ μν xμ’ν μ΄λκ° | ||
int y[4] = { -1,1,0,0 }; // yμ’ν μ΄λκ° | ||
|
||
void dfs(int a,int b,char color[][100], bool visited[][100]) { //x:νμμμ μ’ν,y:νμμμ yμ’ν color:μ μμΈμ νμμΈμ§ μ λ‘μμ½μ νμμΈμ§ | ||
for (int i = 0; i < 4; i++) { | ||
int a2 = a + x[i]; | ||
int b2 = b + y[i]; | ||
if (a2 >= 0 && a2 < siz && b2 >= 0 && b2 < siz && !visited[a2][b2]&&color[a][b]==color[a2][b2]) { | ||
visited[a2][b2] = true; | ||
dfs(a2, b2,color,visited); | ||
} | ||
} | ||
} | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
cin >> siz; | ||
for (int i = 0; i < siz; i++) { //color,clolor2λ°°μ΄μ κ·Έλ¦Όμ μ λ ₯λ°μ μ μ₯ν΄μ€λ€. | ||
cin >> line; | ||
for (int j = 0; j < siz; j++) { | ||
color[i][j] = line[j]; | ||
if (line[j] == 'R') color2[i][j] = 'G'; //μ λ‘μμ½μ μν΄ rμ gλ‘ λ€ λ°κΏμ μ μ₯ν΄μ€λ€. | ||
else color2[i][j] = line[j]; | ||
} | ||
} | ||
|
||
for (int i = 0; i < siz; i++) { //μ μμΈμ νμ | ||
for (int j = 0; j < siz; j++) { | ||
if (!visited[i][j]) { | ||
dfs(i,j,color,visited); | ||
coun++; | ||
} | ||
} | ||
} | ||
for (int i = 0; i < siz; i++) { //μ λ‘μμ½μ νμ | ||
for (int j = 0; j < siz; j++) { | ||
if (!visited2[i][j]) { | ||
dfs(i, j, color2,visited2); | ||
coun2++; | ||
} | ||
} | ||
} | ||
cout << coun <<" "<< coun2; | ||
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,86 @@ | ||
#include<iostream> | ||
#include<vector> | ||
#include<string> | ||
#include<algorithm> | ||
using namespace std; | ||
vector<int>v; //λ°°μ΄μ μμλ€μ μ μ₯ν λ²‘ν° | ||
string a,b,nm; //a-λͺ λ Ήμ΄λ€μ μ μ₯ν string, b-λ°°μ΄μ μ μ₯ν string | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t,num,start_idx,end_idx; //t-ν μ€νΈμΌμ΄μ€κ°μ,num-μμμκ°μ,start_idx-μμ μΈλ±μ€,end_idx-λμΈλ±μ€ | ||
int r_cnt = 0; | ||
cin >> t; | ||
while (t--) { | ||
cin >> a>>num>>b; | ||
start_idx = 0; end_idx = num - 1; | ||
r_cnt = 0; | ||
for (int i = 0; i <b.size(); i++) { | ||
if (b[i] == '[' || b[i] == ']') | ||
continue; | ||
else if (b[i] == ',') | ||
{ | ||
v.push_back(stoi(nm)); | ||
nm.clear(); | ||
} | ||
else | ||
nm = nm + b[i]; | ||
|
||
} | ||
if(!nm.empty()) v.push_back(stoi(nm)); | ||
nm.clear(); | ||
|
||
for (int i = 0; i < a.size(); i++) { | ||
if (a[i] == 'R') | ||
r_cnt++; | ||
else { //dλ₯Όμ€νν κ²½μ° | ||
if (end_idx == -1) //벑ν°λ΄μ μμκ° μλκ²½μ° | ||
{ | ||
r_cnt == 0; | ||
end_idx--; | ||
break; | ||
} | ||
if (r_cnt % 2) { //rμ΄ νμλ²λμμκ²½μ° μμμΈλ±μ€μ λμΈλ±μ€λ₯Ό λ°κΏμ€λ€. | ||
int temp = start_idx; | ||
start_idx = end_idx; | ||
end_idx = temp; | ||
} | ||
if (start_idx > end_idx) | ||
start_idx--; | ||
else if (end_idx > start_idx) | ||
start_idx++; | ||
else end_idx = -1; //μμμΈλ±μ€μ λμΈλ±μ€κ° κ°μκ²½μ°μ μμλ νλμ‘΄μ¬νλ―λ‘ dλ₯Ό μ€νν κ²½μ° λ²‘ν°κ° λΉκ²λλ€. | ||
r_cnt = 0; | ||
} | ||
} | ||
if (r_cnt != 0 && end_idx > -1&&r_cnt%2==1) { //μ μΌλμ rμ΄ μ¬κ²½μ° λΉ λ²‘ν°κ° μλκ³ rμκ°μκ° νμμΌλ | ||
int temp = start_idx; | ||
start_idx = end_idx; | ||
end_idx = temp; | ||
} | ||
|
||
if (end_idx == -2) cout << "error"<<"\n"; | ||
else if (end_idx == -1) cout << "[]"<<"\n"; | ||
else { | ||
cout << "["; | ||
if (start_idx >= end_idx) { | ||
for (int i =start_idx; i>end_idx; i--) { | ||
cout << v[i] << ","; | ||
} | ||
cout << v[end_idx]<<"]"<<"\n"; | ||
} | ||
else { | ||
for (int i = start_idx; i < end_idx; i++) { | ||
cout << v[i] << ","; | ||
} | ||
cout << v[end_idx]<<"]"<<"\n"; | ||
} | ||
|
||
} | ||
|
||
vector<int>().swap(v); //λ€λ₯Έ ν μ€νΈμΌμ΄μ€λ₯Ό μν λ²‘ν° μ΄κΈ°ν | ||
|
||
} | ||
|
||
|
||
} |
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,11 @@ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
dp = [1,2,4,7] | ||
p = 4 | ||
for i in range(int(input())): | ||
n = int(input()) | ||
while(n>p): | ||
dp.append((dp[p-3]+dp[p-2]+dp[p-1])%1000000009) | ||
p+=1 | ||
print(dp[n-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,13 @@ | ||
n,k = map(int,input().split()) | ||
|
||
mod = 1000000000 | ||
|
||
dp = [[0] * (n+1) for _ in range(k+1)] # 2μ°¨μ λ°°μ΄ | ||
dp [0][0] = 1 # μ΄κΈ°κ° μ€μ | ||
|
||
for i in range(1,k+1): | ||
for j in range(n+1): | ||
dp[i][j] = dp[i-1][j] + dp[i][j-1] | ||
dp[i][j] = dp[i][j] % mod | ||
|
||
print(dp[k][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,32 @@ | ||
from collections import deque | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
m = int(input()) | ||
arr = [[0 for i in range(n)] for i in range(n)] | ||
|
||
for i in range(m): | ||
a,b = map(int,input().split()) | ||
arr[a-1][b-1] = 1 # λ Έλ μ μ₯ | ||
arr[b-1][a-1] = 1 | ||
visited = [0 for i in range(len(arr))] | ||
|
||
def bfs(start): | ||
q = deque() | ||
q.append(start) | ||
visited[start] = 1 | ||
while q: | ||
top = q.popleft() | ||
for i in range(len(arr)): | ||
if arr[top][i] == 1 and visited[i] == 0: | ||
visited[i] = visited[top]+1 | ||
q.append(i) | ||
|
||
bfs(0) | ||
re = 0 | ||
for i in visited: | ||
if i==2 or i==3: | ||
re+=1 | ||
print(re) |
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,20 @@ | ||
import math | ||
|
||
n = int(input()) | ||
for i in range(n): | ||
cnt = 0 | ||
k = int(input()) | ||
j = 2 # μ μ΄λ 2κ° μ΄μμ μ°μλ μμ°μμ ν© | ||
while True: | ||
center_first = math.floor(k / j) # center κ°μ μ΄κΈ°ν | ||
div = j // 2 | ||
if center_first < div: | ||
break | ||
if j % 2 == 0: | ||
if ((center_first + center_first + 1) * div == k): | ||
cnt += 1 | ||
elif j % 2 == 1: | ||
if ((center_first * 2 * div + center_first) == k): | ||
cnt += 1 | ||
j += 1 | ||
print(cnt) |
Oops, something went wrong.