-
Notifications
You must be signed in to change notification settings - Fork 1
34-wnsmir #138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ¬Έμ μ체λ₯Ό λμ ν μ΄ν΄ λͺ»νκ² μ΄μ PRμ λ°λ‘ λ΄€λλ°λ μ΄ν΄κ° μκ°μ΅λλ€... κ·Έλμ λ€λ₯Έ λΈλ‘κ·Έλ₯Ό 보λκΉ μμ λ€λ₯Έ λ°©μμΌλ‘ μ κ·ΌνλλΌκ΅¬μ.
λ°©ν₯ μ€λ₯Έμͺ½μ 0, μλ₯Ό 1, μΌμͺ½μ 2, μλμͺ½μ 3μ΄λΌ λ§€ννκ³ λ¬Έμ μμ μ£Όμ΄μ§ μμλ₯Ό νμΈν΄λ³΄λ©΄, μλμ κ°μ΄ μ΄λν©λλ€.
gen 0: 0
gen 1: 0 1
gen 2: 0 1 2 1
gen 3: 0 1 2 1 2 3 2 1
μΈλκ° μ¦κ°ν λλ§λ€ λ°©ν₯ μ λ³΄κ° 2λ°°μ© λμ΄λλλ°, μ΄λ₯Ό λμΉμ μΌλ‘ νμΈν΄λ³΄λ©΄ λ€μκ³Ό κ°μ΅λλ€.
gen 1: 0 1
gen 2: 0 1 / 2 1
gen 2: 0 1 2 1
gen 3: 0 1 2 1 / 2 3 2 1
λ΄λ λͺ¨λ₯΄κ² μ΅λλ€. λ λ€μ΄κ°λ³΄κ² μ΅λλ€. ν λ² λ€μ μΈλμ λ€ μ λ°μ λ€μ§μ΄λ³΄κ² μ΅λλ€.
gen 1: 0 1
gen 2: 0 1 / 1 2
gen 2: 0 1 2 1
gen 3: 0 1 2 1 / 1 2 3 2
μ΄μ μΌ μ’ λ³΄μ λλ€. λ€ μ λ°μ μ΄μ μΈλ λ°©ν₯ μ 보μ +1μ ν κ²μ μμμΌλ‘ λμ΄ν κ²μ λλ€. 3 -> 4λ₯Ό κ°λ κ²½μ°μλ§ λͺ¨λλ¬ μ°μ°μ ν΅ν΄ 0μΌλ‘ λ리면 λ©λλ€.
μ΄κ±°λ₯Ό κΈ°λ°μΌλ‘ μ½λλ₯Ό μμ±νλ©΄ λ€μκ³Ό κ°μ΅λλ€.
Details
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N; cin >> N;
vector<vector<bool>> board(101, vector<bool>(101, false));
array<int, 4> dx{0, -1, 0, 1}; // R U L D
array<int, 4> dy{1, 0, -1, 0};
int x, y, d, g;
while(N--) {
cin >> y >> x >> d >> g;
vector<int> directions;
directions.reserve(1 << g);
board[x][y] = true;
x += dx[d]; y += dy[d];
board[x][y] = true;
directions.push_back(d);
while(g--) {
for(auto it = directions.rbegin(); it != directions.rend(); ++it) {
int nd = (*it + 1) & 0b11;
x += dx[nd]; y += dy[nd];
board[x][y] = true;
directions.push_back(nd);
}
}
}
int ans = 0;
for(int i = 1; i < 100; ++i) {
for(int j = 1; j < 100; ++j) {
if(board[i][j] && board[i + 1][j] && board[i][j + 1] && board[i + 1][j + 1]) {
++ans;
}
}
}
cout << ans;
return 0;
}κ²°λ‘ : shit!
kokeunho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ λ μ΄ λ¬Έμ λ₯Ό λ©°μΉ μ μ νμ΄λ΄€μ΅λλ€.
μ²μ λ΄€μ λ μ λ λμ ν μ΄μ μΈλμ λͺ¨μμ μ΄λ»κ² νμ μμΌμΌν μ§ λ μ¬λ¦΄ μ μμμ΅λλ€.
listμ μ΄λ λ°©ν₯μ λ΄μ΅λλ€.
μΈλκ° λμ΄κ°λ©΄
μ΄μ μΈλ μ΄λ λ°©ν₯ 리μ€νΈμ λ€μμλΆν° μμλ₯Ό λΉΌμ +1νκ³
κ·Έ κ°μ μ΄μ μΈλ μ΄λ λ°©ν₯ 리μ€νΈμ μΆκ°ν©λλ€.
μ
λ ₯ λ°μ μΈλ genμ λλ¬νμλ€λ©΄
μ΄λ λ°©ν₯μ λ°λΌκ°λ©° mapμ λλ곀컀λΈλ₯Ό νμν©λλ€.
λ€ κΌμ§μ μ΄ λλκ³€ 컀λΈμ ν΄λΉνλ μΉΈμ
map[i][j], map[i+1][j], map[i][j+1], map[i+1][j+1]μ κ°μ΄
λͺ¨λ 1μΈ κ²½μ°λ₯Ό μΉ΄μ΄νΈνλ©΄ λ©λλ€.
μ λ μΌμ λ¬Έμ λ₯Ό λͺκ° νμ΄λ³΄κ³ μλλ°
νμ μ μ λ§ μ’μνλ κ² κ°μ΅λλ€.
κ·Έλ°λ° μ λ§ λ€μν νμ μ ꡬνν΄μΌν΄μ νλλ€μ;
μκ³ νμ ¨μ΅λλ€.
Details
import java.io.*;
import java.util.*;
public class Main {
static int N;
static int[][] map = new int[101][101];
static int[] dx = {1, 0, -1, 0};
static int[] dy = {0, -1, 0, 1};
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());
for (int i = 0; i < N; i++) {
st = new StringTokenizer(br.readLine());
int x = Integer.parseInt(st.nextToken());
int y = Integer.parseInt(st.nextToken());
int d = Integer.parseInt(st.nextToken());
int gen = Integer.parseInt(st.nextToken());
dragonCurve(x, y, d, gen);
}
System.out.print(checkBox());
}
static void dragonCurve(int x, int y, int d, int gen) {
List<Integer> path = new ArrayList<>();
path.add(d);
int count = 0;
while (count < gen) {
for (int i = path.size()-1; i >= 0; i--) {
path.add((path.get(i)+1) % 4);
}
count++;
}
map[y][x] = 1;
for (int i : path) {
x += dx[i];
y += dy[i];
map[y][x] = 1;
}
}
static int checkBox() {
int response = 0;
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (map[i][j] == 1 && map[i+1][j] == 1 && map[i][j+1] == 1 && map[i+1][j+1] == 1) {
response++;
}
}
}
return response;
}
}|
μ€ λλ κ³€μ λλ κ³€ μ»€λΈ λ¬Έμ |
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/15685
βοΈ μμλ μκ°
1h
β¨ μλ μ½λ
μμ΄λ₯Ό μ‘κΈ°μ λͺΈνκΈ°λ¬Έμ λ‘ νλ² νμ΄λ³΄μμ΅λλ€.
μ΄ λ¬Έμ μμ μκ°νλμ μ λ± λκ°μ§μμ΅λλ€.
μ€μ¬μ μ΄ μλ μνμμμ νμ , λ§μ§λ§ μ’ν μ¦ λ€μ μ€μ¬μ μ μ΄λ»κ² μ λ°μ΄νΈν΄μ£Όμ΄μΌ ν κ²μΈκ°?
μ€μ¬μ μ΄ μλ νμ μ
μ΄λ κ² μ²λ¦¬ν΄μ£Όμμ΅λλ€.
λ€μ μ€μ¬μ μ μ²λ¦¬νλκ² μ’ μκ°μ΄ λ§μ΄ κ±Έλ Έλλ° μ²μμλ μμμ μμ bfsλ‘ κ°μ₯λ©λ¦¬μλ μ μ μ°Ύμμ λ§€λ² μ λ°μ΄νΈμμΌμ€κΉ νμ§λ§ λ무 ν¬λ¨ΈμΉμΈκ² κ°μ μ’λ μκ°ν΄λ³Έ κ²°κ³Ό
νμ ν΄μ μ 리μ€νΈμ μΆκ°ν΄μ€λ μ€μ¬μ μΌλ‘ λΆν° κ°κΉμ΄μ λ€λΆν° μΆκ°ν΄μ£Όλ©΄ λ§μ§λ§μ μΆκ°λλμ μ΄ λ§μ§λ§μ μ΄ λλ μ μ μ΄μ©νμ΅λλ€.
μ¦ μ€μ¬μ μΌλ‘λΆν° κ°κΉμ΄μ μ λ¨Όμ μΆκ°ν΄μ£Όλ €λ©΄ μ΄μ μΈλμ μ λ€μ λ€μμλΆν° μννλ©° μΈ μΈλ λ€μ νλμ© μΆκ°ν΄μ€λλ€.
κ·ΈλΌ μ μΌ λ§μ§λ§μμκ° λ λ€μ νμ μ μ€μ¬μ μ΄ λ©λλ€.
μ΄ν ꡬνμ μ½κ² νμ€ μ μμκ²λλ€!
I, jλ₯Ό μννλ©° μ€λ₯Έμͺ½, μλ, μ€λ₯Έμͺ½μλ 3μ μ΄ λͺ¨λ 1μ΄λ©΄ answer += 1 νλλ‘ κ°λ¨νκ² κ΅¬ννμ΅λλ€.
(λ μ°νν₯νκΈ° λ΄λ¬Έμ μ€λ³΅μμ)
μ μ°Έκ³ λ‘ x yμ λ°©ν₯μ΄ μΌλ°μ μ΄ λ¬Έμ μλ λ°λμ¬μ μ κ²½μ¨μ£Όμ΄μΌ ν©λλ€.