알고리즘/SW Expert Academy
[SWEA] 1225 암호생성기
세진짱
2020. 2. 3. 19:03
수학 + 큐 문제다
시물레이션으로 풀 수 있는데 숫자 범위가 int다
최악의 경우에 21억이 8개들어오면 대충 7억번? 돌아야한다고 생각하는데
그냥 풀어도 시간안에 들어오나보다
최악의 테케가 없는건지 아니면 내가 잘못생각한거지..!
어쨌든 문제는 5바퀴를돌면 총 15씩 전체적으로 감소시킬 수 있다
그럼 우리가 감소시킬 수 있는만큼 15*k만큼 감소시키자
그리고 시물을 돌리면 편하게 답이 나온다
직접 큐를 사용하지는 않는다 그냥 q의 top이 있다고 생각하고 top을 옮기는게 더 편하다
소스코드
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
|
import java.io.FileInputStream;
public class Solution {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
for(int tc=1;tc<=10;tc++) {
int t = sc.nextInt();
int[] arr = new int[8];
int minn= Integer.MAX_VALUE;
for(int i=0;i<8;i++) {
arr[i] = sc.nextInt();
minn = Math.min(arr[i], minn);
}
minn/=15; minn--; minn*=15;
for(int i=0;i<8;i++) arr[i]-=minn;
int top=0,num=1;
while(true) {
arr[(top++)%8]-=num++;
if(arr[(top+7)%8]<=0) break;
num%=5; if(num==0) num=5;
}
System.out.print("#"+t+" ");
for(int i=top;i<top+8;i++) System.out.print((arr[i%8]<0) ? 0 : arr[i%8]+" ");
System.out.println();
}
}
}
|