Problem/Brute force
[SW Expert Academy] 1208. Flatten
지무룩
2019. 2. 26. 17:22
[SW Expert Academy] 1208. Flatten
문제 링크 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV139KOaABgCFAYh
나의 풀이
1. 빌딩 배열에서 최고점과 최저점을 찾아 최고점에서 1을 감소시키고 최저점에서 1을 증가시킨다.
2. 반환 조건 : 1) 주어진 덤프 횟수이내에 평탄화가 완료되었을 때 : 최고점과 최저점의 차가 0이나 1일 때
2) 덤프 횟수만큼 평탄화 진행을 마쳤을 때
나의 코드
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 | #include<iostream> #include<string.h> using namespace std; int dump; int wall[101]; int main( void ) { for ( int i = 1; i <= 10; i++) { cin >> dump; memset (wall, 0, sizeof ( int )*101); for ( int j = 0; j < 100; j++) cin >> wall[j]; int highest = 0, lowest = 0; for ( int d = 0; d <= dump; d++) { for ( int j = 0; j < 100; j++) { // 최고점 찾기 if (wall[j] > wall[highest]) highest = j; // 최저점 찾기 if (wall[j] < wall[lowest]) lowest = j; } if ((wall[highest] - wall[lowest]) == 1 || (wall[highest] - wall[lowest]) == 0) break ; if (d == dump) break ; wall[highest]--; wall[lowest]++; } cout << '#' << i << ' ' << wall[highest] - wall[lowest] << '\n' ; } return 0; } |