'전체 글'에 해당되는 글 1802건

  1. 2019.08.14 점화식
  2. 2019.08.14 [c#] Predicate<T> Delegate
  3. 2019.08.14 visual studio code 에서 c# 디버깅 하기
  4. 2019.08.13 [백준] 1463 1로 만들기
  5. 2019.08.13 [백준] 11047 동전 0 (진행중)
  6. 2019.08.12 mean stack

점화식

Data structure 2019. 8. 14. 13:21
반응형


수학에서 점화식(漸化式) 또는 재귀식(再歸式, Recurrence relation)이란 인접한 항들 사이의 관계식을 말한다. 

https://ko.wikipedia.org/wiki/%EC%A0%90%ED%99%94%EC%8B%9D

 

점화식 - 위키백과, 우리 모두의 백과사전

위키백과, 우리 모두의 백과사전. 수학에서 점화식(漸化式) 또는 재귀식(再歸式, Recurrence relation)이란 인접한 항들 사이의 관계식을 말한다. 즉, 수열 { a n } {\displaystyle \{a_{n}\}} 의 각 항 a n {\displaystyle a_{n}} 이 함수 f 를 이용해서 a n + 1 = f ( a n ) {\displaystyle a_{n+1}=f(a_{n})} 처럼 귀납적으로 정해져 있을 때, 함수 f 를 수열

ko.wikipedia.org

 

반응형

'Data structure' 카테고리의 다른 글

Binary Search Tree  (0) 2020.05.29
이진 트리  (0) 2019.08.14
이진 탐색 (Binary Search)  (0) 2019.08.14
퀵 정렬( Quick Sort)  (0) 2019.08.14
병합정렬 (Merge Sort)  (0) 2019.08.14
:

[c#] Predicate<T> Delegate

카테고리 없음 2019. 8. 14. 11:51
반응형

 

Predicate<T> Delegate

정의

네임스페이스: System Assemblies:System.Runtime.dll, mscorlib.dll, netstandard.dll

조건 집합을 정의하고 지정된 개체가 이러한 조건을 충족하는지 여부를 확인하는 메서드를 나타냅니다.

C#

public delegate bool Predicate<in T>(T obj); 형식 매개 변수

T

비교할 개체의 형식입니다.

매개 변수

obj

이 대리자가 나타내는 메서드에 정의된 조건과 비교할 개체입니다.

반환 값 System.Boolean

obj가 이 대리자가 나타내는 메서드에 정의된 조건을 충족하면 true이고, 그렇지 않으면 false입니다.

상속

Object

Delegate

Predicate<T>

예제

다음 코드 예제에서는 Predicate<T> 사용 하 여 대리자를 Array.Find 배열을 검색 하는 방법 Point 구조입니다. 이 예제에서는 명시적으로 정의 합니다.를 Predicate<T> 라는 대리자 predicate 라는 메서드를 할당 FindPoints 반환 하는 true 경우를 곱한 값를 Point.XPoint.Y 필드 100,000 보다 큽니다. 일반적인 형식의 대리자를 명시적으로 정의 하기 보다는 람다 식을 사용 하는 Predicate<T>처럼 두 번째 예제를 보여 줍니다.

 

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
32
33
34
35
36
37
38
39
40
41
42
43
44
using System;
using System.Collections.Generic;
 
namespace _04
{
    public class HockeyTeam
    {
        private string name;
        private int founded;
        public HockeyTeam(string name, int year){
            this.name = name;
            this.founded = year;
        }
        public string Name {
            get { return this.name; }
        }
        public int Founded {
            get { return this.founded; }
        }
    }
 
    class Program
    {
        static void Main(string[] args)
        {
            Random rnd = new Random();
            List<HockeyTeam> teams = new List<HockeyTeam>();
            teams.AddRange( new HockeyTeam[]{
                new HockeyTeam("Detroit Red Wings"1926),
                new HockeyTeam("Chicago Blackhawks"1926),
                new HockeyTeam("San Jose Sharks"1991),
                new HockeyTeam("Montreal Canadiens"1909),
                new HockeyTeam("St. Lauis Blues"1967)
            });
            int[] years = { 1920193019802000 };
            int foundedBeforeYear = years[rnd.Next(0years.Length)];
            Console.WriteLine("Teams founded before {0}:", foundedBeforeYear);
            foreach(var team in teams.FindAll(x=>x.Founded <= foundedBeforeYear)){
                Console.WriteLine("{0}: {1}"team.Name, team.Founded);
            }
        }
    }
}
 
 
 
불러오는 중입니다...

 

반응형
:

visual studio code 에서 c# 디버깅 하기

Unity3D/C# 2019. 8. 14. 11:22
반응형

 

새로운 프로젝트를 만든다 (프로젝트 폴더를 미리 생성했을 경우)

dotnet new console

 

새로운 프로젝트를 만든다 (프로젝트 폴더를 생성하지 않았을 경우)

dotnet new console -n <project-name>

 

빌드 하기

dotnet run

 

디버깅 하기

F5

 

디버깅하려면 launch.json, task.json파일이 필요함. (자동생성됨)

launch.json

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
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version""0.2.0",
    "configurations": [
        {
            "name"".NET Core Launch (console)",
            "type""coreclr",
            "request""launch",
            "preLaunchTask""build",
            "program""${workspaceFolder}/04/bin/Debug/netcoreapp2.1/04.dll",
            "args": [],
            "cwd""${workspaceFolder}/04",
            "console""internalConsole",
            "stopAtEntry"false
        },
        {
            "name"".NET Core Attach",
            "type""coreclr",
            "request""attach",
            "processId""${command:pickProcess}"
        }
    ]
}
 
 

 

task.json

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
32
33
34
35
36
37
38
39
40
41
42
{
    "version""2.0.0",
    "tasks": [
        {
            "label""build",
            "command""dotnet",
            "type""process",
            "args": [
                "build",
                "${workspaceFolder}/04/04.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher""$msCompile"
        },
        {
            "label""publish",
            "command""dotnet",
            "type""process",
            "args": [
                "publish",
                "${workspaceFolder}/04/04.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher""$msCompile"
        },
        {
            "label""watch",
            "command""dotnet",
            "type""process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/04/04.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher""$msCompile"
        }
    ]
}
 
 

 

launch.json파일과 task.json파일 생성방법

 

 

반응형

'Unity3D > C#' 카테고리의 다른 글

C# 배열연습  (0) 2020.04.17
구조체(struct) 와 클래스(class)의 차이점  (0) 2019.08.15
(C#) resolving-method-overloads  (0) 2019.04.10
(C#) 타입 비교  (0) 2019.04.05
(C#) Array to Dictionary (Linq)  (0) 2019.04.05
:

[백준] 1463 1로 만들기

Algorithm 2019. 8. 13. 16:17
반응형

https://www.acmicpc.net/problem/1463

 

1463번: 1로 만들기

첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다.

www.acmicpc.net

1로 만들기 성공

2 초 128 MB 80115 26214 16738 32.155%

시간 제한메모리 제한제출정답맞은 사람정답 비율

문제

정수 X에 사용할 수 있는 연산은 다음과 같이 세 가지 이다.

  1. X가 3으로 나누어 떨어지면, 3으로 나눈다.
  2. X가 2로 나누어 떨어지면, 2로 나눈다.
  3. 1을 뺀다.

정수 N이 주어졌을 때, 위와 같은 연산 세 개를 적절히 사용해서 1을 만들려고 한다. 연산을 사용하는 횟수의 최솟값을 출력하시오.

입력

첫째 줄에 1보다 크거나 같고, 106보다 작거나 같은 정수 N이 주어진다.

출력

첫째 줄에 연산을 하는 횟수의 최솟값을 출력한다.

예제 입력 1 복사

2

예제 출력 1 복사

1

예제 입력 2 복사

10

예제 출력 2 복사

3

힌트

10의 경우에 10 -> 9 -> 3 -> 1 로 3번 만에 만들 수 있다.

 

top-down 방식

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace algorithm_11047
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solution();
        }
    }
 
    class Solution {
        int count = 0;
        int[] arr = new int[1000001];
 
        public Solution() {
            var input = Console.ReadLine();
            int n = int.Parse(input);
            this.count = Func(n);
            Console.WriteLine(count);
        }
 
        public int Func(int n) {
            if (n == 1) {
                return 0;
            }
 
            if (arr[n] > 0) {
                return arr[n];
            }
 
            arr[n] = Func(n - 1+ 1;
 
            if (n % 3 == 0)
            {
                var temp = Func(n / 3+ 1;
                if (arr[n] > temp)
                {
                    arr[n] = temp;
                }
            }
 
            if (n % 2 == 0)
            {
                var temp = Func(n / 2+ 1;
                if (arr[n] > temp)
                {
                    arr[n] = temp;
                }
            }
 
 
            return arr[n];
        }
    }
}
 
 
 

 

button-up방식

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
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace algorithm_11047
{
    class Program
    {
        static void Main(string[] args)
        {
            new Solution();
        }
    }
 
    class Solution {
        int[] arr;
 
        public Solution() {
            var input = Console.ReadLine();
            int n = int.Parse(input);
            this.ButtonUp(n);
        }
 
        public void ButtonUp(int n) {
            this.arr = new int[n + 1];
            this.arr[0= this.arr[1= 0;
            for (int i = 2; i <= n; i++) {
                this.arr[i] = this.arr[i - 1+ 1;
                if (i % 2 == 0this.arr[i] = Math.Min(this.arr[i], this.arr[i / 2+ 1);
                if (i % 3 == 0this.arr[i] = Math.Min(this.arr[i], this.arr[i / 3+ 1);
            }
            Console.WriteLine(this.arr[n]);
        }
    }
}
 
 
 
반응형

'Algorithm' 카테고리의 다른 글

재귀와 역추적  (0) 2019.08.14
피보나치 수열  (0) 2019.08.14
[백준] 11047 동전 0 (진행중)  (0) 2019.08.13
[백준] ATM 11399  (0) 2019.08.12
설탕 배달  (0) 2019.06.11
:

[백준] 11047 동전 0 (진행중)

Algorithm 2019. 8. 13. 10:14
반응형

https://www.acmicpc.net/problem/11047

 

11047번: 동전 0

첫째 줄에 N과 K가 주어진다. (1 ≤ N ≤ 10, 1 ≤ K ≤ 100,000,000) 둘째 줄부터 N개의 줄에 동전의 가치 Ai가 오름차순으로 주어진다. (1 ≤ Ai ≤ 1,000,000, A1 = 1, i ≥ 2인 경우에 Ai는 Ai-1의 배수)

www.acmicpc.net

 

 

틀렸습니다????

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const readline = require('readline');
 
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
 
let n;
let k;
let arrN = [];
let state = 0;
rl.on('line', (input)=>{
 
    if(state === 0){
        let arr = input.split(' ');
        n = parseInt(arr[0]);
        k = parseInt(arr[1]);
        console.log(n, k);
    }else{
    }
 
    if(state === n){
        arrN = arrN.reverse(); 
        tempK = k;
        solution(0);
 
        rl.close();
    }
 
    state++;
});
 
let count = 0;
let tempK;
const solution = (i)=>{
 
    if( i >= arrN.length){
        console.log(count)
        return;
    }
 
    let target = parseInt(arrN[i]);
    while(true){
        if( tempK - target < 0)
            break;
 
        tempK -= target;
        count++;
    }
 
    solution(i + 1);
};
 
 

 

 

맞았습니다. (자바)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i, m = 0, n = sc.nextInt(), k = sc.nextInt();
        int a[] = new int[n+1];
        for(i = 1; i<= n; i++) {
            a[i] = sc.nextInt();
        }
        
        for(i = n; i>0; i--) {
            m+= k/a[i];
            k %= a[i];
        }
        System.out.println(m);
        sc.close();
                
    }
}
 
 
 

 

맞았습니다 (C#)

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
using System;
 
namespace _01
{
    class Program
    {
        static void Main(string[] args)
        {
             var input = Console.ReadLine();
            var arr1 = input.Split(' ');
            int n = int.Parse(arr1[0]);
            int k = int.Parse(arr1[1]);
            int[] arr2 = new int[n + 1];
            int i, m = 0;
            for (i = 1; i <= n; i++) {
                arr2[i] = int.Parse(Console.ReadLine());
            }
            for (i = n; i > 0; i--) {
                m += k / arr2[i];
                k %= arr2[i];
            }
            Console.WriteLine(m);
        }
    }
}
 
 
 
반응형

'Algorithm' 카테고리의 다른 글

피보나치 수열  (0) 2019.08.14
[백준] 1463 1로 만들기  (0) 2019.08.13
[백준] ATM 11399  (0) 2019.08.12
설탕 배달  (0) 2019.06.11
그래프  (0) 2019.06.11
:

mean stack

Sever 2019. 8. 12. 16:53
반응형

https://www.a-mean-blog.com/ko/blog/%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A1%9C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D-%EC%9E%85%EB%AC%B8?group=JS

 

자바스크립트로 프로그래밍 입문 - A MEAN Blog

 

www.a-mean-blog.com

 

반응형

'Sever' 카테고리의 다른 글

마이크로서비스  (0) 2019.01.30
카페24 node.js + mysql  (0) 2019.01.10
[Spring Boot] Security InMemory "PasswordEncoder Error"  (0) 2018.05.03
[Spring Boot] There is no PasswordEncoder mapped for the id "null"  (0) 2018.05.02
Tomcat에러  (0) 2018.04.30
: