codeforces_ 158B_ Taxi
https://codeforces.com/problemset/problem/158/B
풀이방법
1. 4명, 3명, 2명인 그룹을 먼저 태운다
ans = numOfGroup[4] + numOfGroup[3] + numOfGroup[2]/2;
2. 1명인 그룹, 2명인 그룹을 위에 맞춰 끼워탄다. ( 1번은 3번에 2번은 2번끼리 )
numOfGroup[1] -= numOfGroup[3];
numOfGroup[2] -= (numOfGroup[2] / 2)*2;
3. 2명인 그룹, 1명인 그룹이 남았으면 그에 맞춰 계산한다.
if (numOfGroup[2] > 0)
{
ans += 1;
numOfGroup[1] -= 2;
}
if (numOfGroup[1] > 0)
{
ans += (numOfGroup[1] / 4);
if (numOfGroup[1] % 4 != 0)
ans += 1;
}
전체코드
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int numOfGroup[5];
int main()
{
int n;
cin >> n;
int value, ans = 0;
for (int i = 0; i < n; i++)
{
cin >> value;
numOfGroup[value]++;
}
ans = numOfGroup[4] + numOfGroup[3] + numOfGroup[2]/2;
numOfGroup[1] -= numOfGroup[3];
numOfGroup[2] -= (numOfGroup[2] / 2)*2;
if (numOfGroup[2] > 0)
{
ans += 1;
numOfGroup[1] -= 2;
}
if (numOfGroup[1] > 0)
{
ans += (numOfGroup[1] / 4);
if (numOfGroup[1] % 4 != 0)
ans += 1;
}
cout << ans;
return 0;
}
후기
아무리 쉬운 영어 지문이라도 조건 하나하나 꼼꼼하게 읽기가 쉽지않다.ㅠ