Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 재귀함수
- dp
- 네트워크플로우
- 백준코딩테스트
- 세그먼트트리
- 게더타운시작
- 엘라스틱서치
- COSPROJAVA1급
- 구현
- 시뮬레이션
- COSPRO
- 우선순위큐
- 이젠 골드구현도 어렵네..
- java
- 01BFS
- deque
- 알고리즘
- PS
- 취득후기
- GatherTown
- 백준
- DFS
- QUICKSTARTGUIDE
- 다익스트라
- BFS
- spring
- 자바PS
- 다이나믹프로그래밍
- 완전탐색
- YBMCOS
Archives
- Today
- Total
공부공간
SWEA ) 대관이의 대량할인 본문
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
재관이는 3벌을사면 3벌중 가장 싼 옷을 무료로 받을수 있다.
예를들어서 10 7 8 4 2 2 4 옷을 사면
나올수 있는 조합에서 가장싸게 구하는 경우를 답으로 채택하면 된다.
잘 생각해보면 세일을 크게 받는 경우는 가격이 비싼 옷끼리 묶어 사는경우이다.
자연스럽게 배열의 정렬을 떠올리게되고 뒤에서부터 3번째 경우에만 따로 합을구해서
전체합에서 빼면끝!
이런건 5분내로 푸는습관을 들이자..
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
|
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class 대량세일 {
static int answer = 0;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st= new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(st.nextToken());
for(int tc = 1; tc<= t ; tc++) {
st = new StringTokenizer(br.readLine());
int sum = 0;
int n = Integer.parseInt(st.nextToken());
int num[] = new int[n];
st = new StringTokenizer(br.readLine());
for(int index = 0 ; index < n ; index++){
num[index] = Integer.parseInt(st.nextToken());
sum+= num[index];
}
int sub =0;
for(int index =n-3 ; index >=0 ; index-=3){
sub += num[index];
}
answer = sum - sub;
answer= 0;
}
System.out.println(sb);
}
}
|
'알고리즘 > 구현,시뮬' 카테고리의 다른 글
JUNGOL - 1828 ) 냉장고 (0) | 2020.02.13 |
---|---|
Algorithm 풀이를 위한 JAVA 자료구조 정리 (2) | 2020.02.10 |
SWEA ) 줄기세포 배양 (2) | 2020.02.09 |
BOJ - 14890 ) 경사로 (0) | 2020.02.07 |
Jungol - 1141 ) 불쾌한 날(Bad Hair Day) (0) | 2020.02.03 |
Comments