250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 백준으로 C++ 공부
- 1654
- C++
- openai api
- 알고리즘
- 백준 C++
- 코딩
- C++ 공부
- iles dHyeres
- 백준
- 피르스트 자전거
- 로이커바트
- 로이커바트 숙소
- porquerolles
- 융프라우 스위스 패스
- 24524
- 그린델발트 자전거
- 시뮬레이션
- 대학생
- C++ 공부하기
- 군대코딩
- 군인
- 프랑스 남부 섬
- 16236 c++
- 군대
- Replit
- 오리스프
- 백준으로 c++ 공부하기
- 그린델발트 캠핑장
- auto code review
Archives
- Today
- Total
기억보다는 기록을 해볼까
[백준 2448] 별 찍기 - 11 (C++) - 49 본문
728x90
문제
https://www.acmicpc.net/problem/2448
2448번: 별 찍기 - 11
첫째 줄에 N이 주어진다. N은 항상 3×2k 수이다. (3, 6, 12, 24, 48, ...) (0 ≤ k ≤ 10, k는 정수)
www.acmicpc.net
생각
평행이동을 기본적으로 생각했다.
첫 별을 찍고
그 이후부터는 꼭대기에서 바닥까지 훑어서 해당 좌표들을 왼쪽과 오른쪽으로 평행이동을 해 별을 찍었다.
코드
#include <bits/stdc++.h>
using namespace std;
int n;
char star[10000][10000];
bool rtrn = false;
void input(int m) {
for(int i = 0; i < m; i++) {
for(int j = n - 1 - (m/2 - 1); j <= n - 1 + (m/2 - 1); j++) {
//평행이동
star[i + m/2][j - m/2] = star[i][j];
star[i + m/2][j + m/2] = star[i][j];
}
}
if(m == n || rtrn) {
rtrn = true;
return;
}
input(m * 2);
}
int main() {
cin >> n;
int k = log2((n / 3));
memset(star, ' ', sizeof(star));
//처음 별 찍기
int s = 3 * pow(2, k) - 1;
star[0][s] = '*';
star[1][s - 1] = '*';
star[1][s + 1] = '*';
for(int i = 0; i < 5; i++) star[2][s + 2 - i] = '*';
//별 출력하기
if(n == 3) {
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 6; j++) {
cout << star[i][j];
}
cout << "\n";
}
}
else{
input(6);
for(int i = 0; i < n; i++) {
for(int j = 0; j < 2*n; j++) {
cout << star[i][j];
}
cout << "\n";
}
}
}
근데 찾아보니 나보다 훨씬 간단하게 잘 풀 사람들이 많다
https://www.acmicpc.net/source/37474436
#include <iostream>
using namespace std;
char arr[3072][6144];
void solve (int n, int x, int y)
{
if (n == 3)
{
arr[x][y] = '*';
arr[x + 1][y - 1] = '*';
arr[x + 1][y + 1] = '*';
for (int i = y - 2; i <= y + 2; i++)
arr[x + 2][i] = '*';
return ;
}
n /= 2;
solve(n, x, y);
solve(n, x + n, y - n);
solve(n, x + n, y + n);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < 2 * n - 1; j++)
arr[i][j] = ' ';
solve(n, 0, n - 1);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 2 * n - 1; j++)
cout << arr[i][j];
cout << '\n';
}
}
728x90
'백준으로 C++ 공부하기' 카테고리의 다른 글
[백준 11404] 플로이드 (C++) - 50 (0) | 2022.01.16 |
---|---|
[백준 2638] 치즈 (C++) - 50 (0) | 2022.01.16 |
[백준 2206] 벽 부수고 이동하기 (C++) - 48 (0) | 2022.01.13 |
[백준 내려가기] 2096 (C++) - 48 (0) | 2022.01.12 |
[백준 1967] 트리의 지름 (C++) - 47 (0) | 2022.01.11 |
Comments