본문 바로가기
728x90

전체 글239

[자료구조] 그래프 BFS(너비우선탐색) 그래프의 탐색 -길이우선탐색(DFS) : 자식까지 탐색 후 다른 형제 노드를 탐색 -너비우선탐색(BFS) : 자식 전에 모든 현재 노드를 탐색_Tree Node의 label 탐색과 같음 방문테이블과 Queue를 사용하여 탐색 C# using System; using System.Collections.Generic; using System.Text; namespace BFSpractice { class Program { static int[,] map = { { 0, 1, 1, 0, 0, 0, 0 }, { 1, 0, 0, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 1, 1 }, { 0, 1, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0.. 2023. 1. 30.
[Unity 2D] 스와이프 예제 변형 StarController using System.Collections; using System.Collections.Generic; using UnityEngine; public class StarController : MonoBehaviour { private float speed = 0; private Vector2 startPos; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { this.startPos = Input.mousePosition; } else if (Input.G.. 2023. 1. 30.
[Unity 2D / 유니티 교과서] 4장 예제 SwipeCar AudioSource mp3파일이 아닌 ogg파일로 변경해서 사용하기! ( 용량 최소 약 1/5로 줄음) Input.mousePosition Unity공간 좌표가 아니라 실행화면의 Screen(픽셀공간) 좌표 죄표계는 3D, Screen, UI 각각 존재 Awake 이벤트 함수. (활성화된 오브젝트에서!)인스턴스 생성 직후 실행. Start보다 먼저 실행 transform.Translate(x, y, z, Space.self/world) 로컬 좌표. 월드 좌표GameObject.Find("string") Scene안에 있는 GameObject 이름 검색(오타 주의) CarController using System.Collections; using System.Collections.Generic; usin.. 2023. 1. 30.
[Unity 2D / 유니티교과서] 3장 예제 Roulette using System.Collections; using System.Collections.Generic; using UnityEngine; public class RouletteController : MonoBehaviour { private float rotSpeed = 0; public float attenuation = 0.96f; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { if (Input.GetMouseButtonDown(0)) { this.rotSpeed = 10; } //오브젝트를 회전 하는 방법 //회전은 Transform이.. 2023. 1. 30.
[C# 알고리즘] 무방향 그래프 2차원 배열로 구현하기 1: 서울 2: 대구 3: 대전 4: 부산 가중치 x using System; using System.Linq; namespace Graph { class Node { public string data; public Node(string data) { this.data = data; } } class Graph { private Node[] nodes; int[,] maps; public Graph(int n) { this.nodes = new Node[n]; maps = new int[n+1, n+1]; } public void AddVertex(Node node) { this.nodes.Append(node); } public void AddEdge(int n0, int n1) { maps[n0, n.. 2023. 1. 30.
[자료구조] (이진)이분탐색 Binary Search 이분탐색이란? 배열에서 내부의 데이터들이 정렬되어 있을 때, 혹은 정렬할 수 있는 데이터들을 가질 때 특정한 수를 찾기 위한 방법 1) 배열의 중간값을 변수에 할당 2) 변수와 찾으려는 값을 비교 3) -1 변수가 더 크다면) 왼쪽의 데이터들의 중간값을 다시 변수에 할당 -2 변수가 더 작다면) 오른쪽의 데이터들의 중간값을 다시 변수에 할당 시간복잡도 데이터가 N개인 배열에서 최악의 경우에도 시간복잡도는 O(logN) (밑이 2) 코드 구현 C# using System; using System.IO; namespace BinarySearch { class Program { static void Main(string[] args) { StreamReader sr = new StreamReader(Conso.. 2023. 1. 30.
[BOJ C#] 1439 뒤집기 중간에 count 확인하려 출력했던 코드를 안지워서 틀렸다..실제로는 이런 실수 안하도록 조심하기!! using System; namespace _1439 { class Program { static void Main() { string str = Console.ReadLine(); int n; int count0 = 0; int count1 = 0; if (str[0] == '0') { n = 0; count0++; } else { n = 1; count1++; } for (int i = 1; i < str.Length; i++) { if (str[i-1] == '0' && str[i] == '1') { n = 1; count1++; } else if (str[i-1] == '1' && str[i] =.. 2023. 1. 28.
[BOJ C#] 5585 거스름돈 using System; namespace _5585 { class Program { static void Main() { int price = int.Parse(Console.ReadLine()); int charge = 1000 - price; int count = 0; while (charge > 0) { if (charge >= 500) { count += (charge / 500); charge %= 500; } else if (charge >= 100) { count += (charge / 100); charge %= 100; } else if (charge >= 50) { count += (charge / 50); charge %= 50; } else if (charge >= 10) { co.. 2023. 1. 27.
[BOJ C#] 1259 팰린드롬수 using System; using System.Linq; using System.Text; using System.IO; namespace _1259 { class Program { static void Main() { StreamReader sr = new StreamReader(Console.OpenStandardInput()); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); StringBuilder sb = new StringBuilder(); while (true) { string str = sr.ReadLine(); if (str == "0") break; string strReverse = new string(str.Re.. 2023. 1. 26.
[ C# ] 인벤토리 구현 App Class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace cshNHR { class App { //생성자 public App() { Inventory inventory = new Inventory(2); inventory.AddItem(new Weapon("장검")); inventory.AddItem(new Weapon("장검")); inventory.AddItem(new Weapon("단검")); inventory.AddItem(new Weapon("창")); inventory.AddItem(new Armor("가죽옷".. 2023. 1. 26.
[BOJ C#] 1085 직사각형에서 탈출 using System; using System.IO; namespace _1085 { class Program { static void Main() { StreamReader sr = new StreamReader(Console.OpenStandardInput()); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); string[] arrString = sr.ReadLine().Split(' '); int x = int.Parse(arrString[0]); int y = int.Parse(arrString[1]); int w = int.Parse(arrString[2]); int h = int.Parse(arrString[3]); in.. 2023. 1. 25.
[BOJ C#] 4153 직각삼각형 using System; using System.Collections.Generic; using System.Text; using System.IO; namespace _4153 { class Program { static void Main() { StreamReader sr = new StreamReader(Console.OpenStandardInput()); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); StringBuilder sb = new StringBuilder(); List arr = new List(); while(true) { string[] arrString = sr.ReadLine().Split(' '); int .. 2023. 1. 25.
728x90