문제
이문제의 포인트는 '문제에서 조어진 조건'이라고 생각한다.
배열에 수를 넣고 입력받은 우선순위를 토대로 하나라고 높은 문서가 있으면 Queue 가장 뒤에 위치시킨다.
Order는 등수저장 배열, checked는 순위가 입력되었는지에 대한 배열 이러한 것들을 사용하여 문제를 풀었다.
세부내용은 Comment를 추가하였다.
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
|
import java.util.StringTokenizer;
public class Main{
public static int [] priority;
public static boolean [] checked;
public static int [] order;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int number=sc.nextInt();
for(int i=0;i<number;i++)
{
int N=sc.nextInt();
int M=sc.nextInt();
priority=new int [N];
checked=new boolean [N];
order= new int [N];
Queue <Integer> queue =new LinkedList<Integer>();
for(int j=0;j<N;j++)
{
queue.add(j);
priority[j]=sc.nextInt();
}
int ak=1;//처음 시작
while(!queue.isEmpty())
{
int index=0;//처음시작
boolean check=false;
while(true)
{
if(index>=N) //escape section
{
break;
}
if(index==temp) //같은것끼리 비교할 필요 X
{
index++;
continue;
}
if(checked[index]) //예제 3번과 같은경우 이미 방문한곳이라면 갈필요 X
{
index++;
continue;
}
if(priority[temp]<priority[index]) //돌면서 하나라도 크면 조건 2에해당함
{
queue.add(temp);
check=true;
break;
}
index++;
}
if(check==false)
{
checked[temp]=true;
order[temp]=ak++;
}
}
System.out.println(order[M]);
}
}
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
https://www.acmicpc.net/problem/1966
1966번: 프린터 큐
문제 여러분도 알다시피 여러분의 프린터 기기는 여러분이 인쇄하고자 하는 문서를 인쇄 명령을 받은 ‘순서대로’, 즉 먼저 요청된 것을 먼저 인쇄한다. 여러 개의 문서가 쌓인다면 Queue 자료구조에 쌓여서 FIFO - First In First Out - 에 따라 인쇄가 되게 된다. 하지만 상근이는 새로운 프린터기 내부 소프트웨어를 개발하였는데, 이 프린터기는 다음과 같은 조건에 따라 인쇄를 하게 된다. 현재 Queue의 가장 앞에 있는 문서의 ‘중요도’를
www.acmicpc.net