RUBY

[BOJ] 시험 감독 | 삼성 본문

PS/BOJ

[BOJ] 시험 감독 | 삼성

RUBY_루비 2020. 9. 12. 23:59

출처:: https://www.acmicpc.net/problem/13458

 

1. 문제 이해 및 해결과정

 

  1. 각 시험장의 응시자 수를 배열에 넣음 

  2. 각 응시자 수를 총 감독 인원 수로 나눠서 CNT+=몫

  3. 응시자 수에서 총감독이 감독한 인원 뺌 

  4. 응시자 수에서 총 감독 인원수 뺀 값에서 부감독 인원수로 나눈 몫의 올림을 더함 CNT+= 몫의 올림

 

*주의할 점 

-시험장 수 * 각 시험장의 최대 학생수 = 10^ 12 ->int형 범위 넘음  => total은 long long %lld 써야함 

 

2. 풀이방법

 1. ceil 올림 함수 이용

#if 01
//시험 감독
//https://www.acmicpc.net/problem/13458
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

vector <int> v;
int N,B,C;
long long total; 
void Solve() {

	for (int i = 0; i < N; i++) {
		total++; //총감독관
	
		v[i] -= B;
		
		if(v[i]>=0)total += (ceil((double)v[i] / C));
	}
}
int main() {

	freopen("input.txt", "r", stdin);
	scanf("%d", &N);

	for (int i = 0; i < N; i++) {
		int people;
		scanf("%d", &people);
		v.push_back(people);
	}

	scanf("%d %d", &B, &C);

	Solve();

	printf("%lld", total);

	return 0;
}
#endif

 

  2. 올리는 경우 직접구현

void Solve() {

	for (int i = 0; i < N; i++) {
		total++; //총감독관
	
		v[i] -= B;
		
		//if(v[i]>=0)total += (ceil((double)v[i] / C));

		if (v[i] > 0) {
			total += (v[i] / C);

			if (v[i] % C != 0) {
				total++;
			}
		}
	}
}

 3. python

#시험감독
#https://www.acmicpc.net/problem/13458
import sys
sys.stdin = open("input.txt","r")
n=int(input()) #시험장
arr=list(map(int,input().split()))
main,sub=map(int,input().split())
sol=0

for x in arr:
    if x>=main: #총감독보다 시험보는 인원이 많으면
        x-=main
        if x%sub==0:
            sol+=x//sub
        else:
            sol+=x//sub + 1
print(sol + len(arr))

 

3. 오답원인

 

4. 알게된 점

 

'PS > BOJ' 카테고리의 다른 글

[백준] 줄세우기  (0) 2020.09.15
[백준] 드래곤 커브 | 삼성  (0) 2020.09.14
[백준] 게리맨더링2 | 삼성  (0) 2020.09.11
[백준] 감시 | 삼성  (0) 2020.09.09
[백준] 치즈  (0) 2020.09.02
Comments