일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- bytecode
- 심리학
- opcode
- 버킷리스트
- Navigation Component
- 보안
- 일상탈출
- 심리여행
- Shared Elements
- 취약점
- ㅇ
- throws
- 회피
- Interface
- bytecode 분석
- Recylcer
- 보안취약점
- HelloWorld
- static
- javap
- 여행계획
- Transition
- jvm
- 일상회피
- Android
- IMPLEMENT
- 치유
- extends
- 여행
- abstract
Archives
- Today
- Total
패스트터틀
(Baekjoon) GreedyAlgorithm - (5) 로프 본문
https://www.acmicpc.net/problem/2217
2217번: 로프
N(1≤N≤100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하지만 여러 개의 로프를 병렬로 연결하면 각각의 로프에 걸리는 중량을 나눌 수 있다. k개의 로프를 사용하여 중량이 w인 물체를 들어올릴 때, 각각의 로프에는 모두 고르게 w/k 만큼의 중량이 걸리게 된다. 각 로프들에 대한 정보가 주어졌을 때, 이 로프들을
www.acmicpc.net
package GreedyAlgorithm;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
/*
2
10
15
1500
2000
3000
4000
5000
가장큰것은 혼자 들면 5000
그보다 낮은것을 합해서 들면 4000 * 2
그보다 낮은것을 더해서 들면 3000 * 3
...
*/
public class _2217{
public static void main(String[] args) {
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(br.readLine());
List<Integer> list = new ArrayList<Integer>();
List<Integer> sum = new ArrayList<Integer>();
for (int i = 0; i < count; i++) {
list.add(i,Integer.parseInt(br.readLine()));
}
Collections.sort(list,Collections.reverseOrder());
for (int i = 0; i < list.size() ; i++) {
sum.add(i,list.get(i) * (i+1) );
}
Collections.sort(sum);
System.out.println(sum.get(sum.size() - 1));
} catch (IOException e){
e.printStackTrace();
}
}
}
참고로 문제 이해하는데 걸린시간이 푸는시간보다 더 많다.
주석 참고하기
백준문제풀이Github :
https://github.com/sdk0213/baekjoon-study
sdk0213/baekjoon-study
solve a baekjoon question. Contribute to sdk0213/baekjoon-study development by creating an account on GitHub.
github.com
'Algorithm > baekjoon' 카테고리의 다른 글
(Baekjoon) GreedyAlgorithm - (7) 대회 or 인턴 (0) | 2019.11.07 |
---|---|
(Baekjoon) GreedyAlgorithm - (6) 30 (0) | 2019.11.07 |
(Baekjoon) GreedyAlgorithm - (4) 거스름돈 (0) | 2019.11.06 |
(Baekjoon) GreedyAlgorithm - (3) 회의실배정 (0) | 2019.11.05 |
(Baekjoon) GreedyAlgorithm - (2) 동전 0 (0) | 2019.11.04 |
Comments