본문 바로가기

분류 전체보기27

[python] 백준 2630번 - 색종이 만들기 모두 같은 색이 나올 때 까지 색종이를 잘라서 각각의 종이의 개수를 구하는 분할정복 문제이다. import sysinput = sys.stdin.readlinedef f(x, y, N): global white, blue c = paper[x][y] same_color = True for i in range(x, x + N): for j in range(y, y + N): if c != paper[i][j]: same_color = False break if not same_color: break if same_color: if c =.. 2024. 8. 11.
[python] 백준 11279번 - 최대 힙 최대 힙을 구현하는 문제. import sysimport heapqinput = sys.stdin.readlineN = int(input())heap = []for _ in range(N): x = int(input()) if x == 0: if len(heap) > 0: print(-heapq.heappop(heap)) else: print(0) else: heapq.heappush(heap, -x)heapq 모듈을 사용하면 힙 자료구조를 간편하게 사용할 수 있지만,최소 힙밖에 제공되지 않는다. 따라서 최대 힙을 구현하기 위해서는 원소를 저장할 때 마이너스 부호를 붙여간단하게 최대 힙을 구현할 수 있다. 2024. 8. 11.
[python] 백준 1629번 - 곱셈 A^B%C를 구하는 문제.단순하게 쓰면 시간초과가 난다. 이 문제를 풀기 위해서는 두 가지의 개념을 알아야 한다. 분할정복(Divide and Conquer)을 활용한 거듭제곱분할정복을 사용하면 거듭제곱을 빠르게 할 수 있다.보통의 거듭제곱은 x를 n번 곱하기 때문에 시간복잡도가 O(N)이 된다. 하지만 다음과 같은 식을 통해 분할정복을 사용한다면 O(logN)으로 거듭제곱을 할 수 있다.다음은 이 식을 구현한 코드이자 이 문제의 정답이다,import sysinput = sys.stdin.readlineA, B, C = map(int, input().split())def pow(a, b): if b == 0: return 1 tmp = pow(a, b // 2) if b % .. 2024. 8. 5.
[Unity] 캐릭터 이동 using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.SceneManagement;public class PlayerController : MonoBehaviour{ public float speed = 3; Vector3 move; void Start() { } // Update is called once per frame void Update() { move = Vector3.zero; if (Input.GetKey(KeyCode.A)) { move += new Vector3.. 2024. 8. 2.
[C#] 문법 정리 2 컬렉션(Collection)컬렉션은 여러 개의 객체를 관리하는데 사용되는 클래스들의 집합이다.배열과 다르게 크기가 정해져 있지 않다. 컬렉션의 종류로는 List, Dictionary, Queue, SortedList, Stack, ArrayList 등이 있다. List유니티에서 List는 다양한 게임 오브젝트와 컴포넌트를 관리하는 데 자주 사용된다.ex) 여러 개의 적 캐릭터 관리, 인벤토리 시스템 구현using System;using System.Collections.Generic;class Program{ static void Main() { // List 생성 및 초기화 List numbers = new List { 1, 2, 3, 4, 5 }; .. 2024. 7. 23.
[python] 백준 9012번 - 괄호 주어진 괄호 문자열이 올바른 괄호 문자열 VPS인지 아닌지 판단하는 문제. 스택이 어떤식으로 활용 되는지 감이 잡히는? 문제인 것 같다.import sysinput = sys.stdin.readlinedef isVPS(s): stack = [] for i in s: if i == "(": stack.append(i) elif i == ")": if len(stack) == 0: return False else: del(stack[-1]) if len(stack) == 0: return True else: return F.. 2024. 7. 22.