cf158B(水题)

题意:1辆出租车可以坐4人,已知k组人每组ki(ki<=4)人去坐车,要求同组人坐同一辆车,求最少需多少辆车。。

4人组的单独算,1人组和3人组一起,如1多余再将1和2匹配即可。。。。

代码如下:

 1 #include <iostream>
 2 #include <string.h>
 3 #include <math.h>
 4 using namespace std;
 5 
 6 int main(void)
 7 {
 8     int n, ans=0;
 9     int a[5];
10     cin >> n;
11     memset(a, 0, sizeof(a));
12     while(n--)
13     {
14         int x;
15         cin >> x;
16         a[x]++;
17     }
18     if(a[1]>a[3])
19     {
20         ans+=a[3];
21         a[1]-=a[3];
22         if(a[2]>a[1])
23         {
24             ans+=floor(a[1]*1.0/2+0.5);
25             a[2]-=floor(a[1]*1.0/2+0.5);
26             ans+=floor(a[2]*1.0/2+0.75);
27         }
28         else
29         {
30             ans+=a[2];
31             a[1]-=2*a[2];
32             ans+=floor(a[1]*1.0/4+0.75);
33         }
34         ans+=a[4];
35     }
36     else
37     {
38         ans+=a[1];
39         a[3]-=a[1];
40         ans+=a[3];
41         ans+=a[4];
42         ans+=floor(a[2]*1.0/2+0.75);
43     }
44     cout << ans << endl;
45     return 0;
46 }

 

转载于:https://www.cnblogs.com/geloutingyu/p/5734483.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值