Data structure 2019. 8. 14. 13:21
카테고리 없음 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.X 및 Point.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 = { 1920 , 1930 , 1980 , 2000 };
Console .WriteLine ("Teams founded before {0}:" , foundedBeforeYear);
foreach (var team in teams.FindAll(x= > x.Founded < = foundedBeforeYear)){
}
}
}
}
불러오는 중입니다...
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.
"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" ,
"/property:GenerateFullPaths=true" ,
"/consoleloggerparameters:NoSummary"
],
"problemMatcher" : "$msCompile"
},
{
"label" : "publish" ,
"command" : "dotnet" ,
"type" : "process" ,
"args" : [
"publish" ,
"/property:GenerateFullPaths=true" ,
"/consoleloggerparameters:NoSummary"
],
"problemMatcher" : "$msCompile"
},
{
"label" : "watch" ,
"command" : "dotnet" ,
"type" : "process" ,
"args" : [
"watch" ,
"run" ,
"/property:GenerateFullPaths=true" ,
"/consoleloggerparameters:NoSummary"
],
"problemMatcher" : "$msCompile"
}
]
}
launch.json파일과 task.json파일 생성방법
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에 사용할 수 있는 연산은 다음과 같이 세 가지 이다.
X가 3으로 나누어 떨어지면, 3으로 나눈다.
X가 2로 나누어 떨어지면, 2로 나눈다.
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;
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;
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 = = 0 )
this .arr[i]
= Math.Min( this .arr[i],
this .arr[i
/ 2 ]
+ 1 );
if (i %
3 = = 0 )
this .arr[i]
= Math.Min( this .arr[i],
this .arr[i
/ 3 ]
+ 1 );
}
Console .WriteLine (this .arr[n]);
}
}
}
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({
});
let n;
let k;
let arrN = [];
let state = 0 ;
if (state = = = 0 ){
n = parseInt(arr[0 ]);
k = parseInt(arr[1 ]);
}else {
}
if (state = = = n){
arrN = arrN.reverse();
tempK = k;
solution(0 );
}
state+ + ;
});
let count = 0 ;
let tempK;
const solution = (i)= > {
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) {
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];
}
}
}
맞았습니다 (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();
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);
}
}
}