您的位置:首页 > 其它

CF - 158B - Taxi

2013-03-31 21:25 176 查看
题意:有n群小朋友要乘车,每群小朋友的人数最少1人,最多4人,一辆车最多可以坐4人,同一个群的小朋友必须坐同一辆车,问最少需要多少辆车。

题目链接:http://codeforces.com/problemset/problem/158/B

——>>贪心,读入时统计各团人数,4人的肯定要一车;3人的也肯定要一车,且能加1人就多加1人;2人的两两一车,最后若剩有1团2人的,则其占1车且能加1人就多加1人;最后1人1人的4个团一车。

#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 100000 + 10;
int s[maxn];

int main()
{
int n, i;
while(~scanf("%d", &n))
{
int one = 0, two = 0, three = 0, four = 0;
for(i = 0; i < n; i++)
{
scanf("%d", &s[i]);
switch(s[i])
{
case 1:one++;break;
case 2:two++;break;
case 3:three++;break;
case 4:four++;break;
}
}
int cnt = four + three + two/2;
if(one > three) one -= three;
else one = 0;
two %= 2;
if(two == 1)
{
cnt++;
if(one > 2) one -= 2;
else one = 0;
}
cnt += one / 4;
if(one % 4 != 0) cnt++;
printf("%d\n", cnt);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: