zoukankan      html  css  js  c++  java
  • 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 }
    我就是我,颜色不一样的烟火 --- geloutingyu
  • 相关阅读:
    今天,你ak了吗?①
    线段树模板
    DP(关于字符串,数字串的)
    Leedsdiscussion
    高数积分求旋转体体积
    tiny mission
    莫队+数组低级化的 优先队列
    LAB2
    Leedslecturepronouncation
    Eclipse Access Restriction
  • 原文地址:https://www.cnblogs.com/geloutingyu/p/5734483.html
Copyright © 2011-2022 走看看