forked from wotjd4305/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproGreedy1.java
More file actions
110 lines (89 loc) · 2.54 KB
/
proGreedy1.java
File metadata and controls
110 lines (89 loc) · 2.54 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class proGreedy1{
static boolean possiable[];
static boolean lostBoolean[];
static boolean reserveBoolean[];
static int answer = 0;
public static void main(String[] args) {
int n = 5;
int[] lost = {2,4};
int[] reserve = {1,3,5};
System.out.println(solution(n,lost,reserve));
}
public static int solution(int n, int[] lost, int[] reserve)
{
possiable = new boolean[n+1];
lostBoolean = new boolean[n+1];
reserveBoolean = new boolean[n+1];
setLost(lost);
setReserve(reserve);
setLostMinusReserve(n);
findStudent(n);
return answer;
}
public static void setLost(int lost[])
{
for(int i =0; i<lost.length; i++)
{
System.out.println("set Lost " + lost[i]);
lostBoolean[lost[i]] = true;
}
}
public static void setReserve(int reserve[])
{
for(int i =0; i<reserve.length; i++)
{
System.out.println("set Reserve " + reserve[i]);
reserveBoolean[reserve[i]] = true;
}
}
public static void setLostMinusReserve(int n)
{
for(int i =1; i<=n; i++)
{
//여분이있지만 털린애
if(reserveBoolean[i] == true)
if(lostBoolean[i] == true)
{
reserveBoolean[i] = false;
lostBoolean[i] = false;
System.out.println("ssss"+i);
}
}
}
public static void findStudent(int n)
{
//가능성 셋팅
for(int i=1; i<=n; i++)
{
if(lostBoolean[i] == false)
{
System.out.println("find" + i);
possiable[i]= true;
}
}
for(int i=1; i<=n; i++)
{
//잃어버린애고
if(lostBoolean[i] == true)
//범위를 넘지 않으며 뒤에 애가 여분이 있으면
if((i+1 != n+1) && (reserveBoolean[i+1] == true))
{
reserveBoolean[i+1] = false;
lostBoolean[i] = false;
}
}
//lostBoolean이 true인(체육복을 가진)수 계산
for(int i=1; i<=n; i++)
{
if(lostBoolean[i] == false)
{
System.out.println("last" + i);
answer++;
}
}
}
}