/*

After the lessons n groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the i-th group consists of si friends (1 ≤ si ≤ 4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)?

Input

The first line contains integer n (1 ≤ n ≤ 105) — the number of groups of schoolchildren. The second line contains a sequence of integers s1, s2, ..., sn (1 ≤ si ≤ 4). The integers are separated by a space, si is the number of children in the i-th group.

Output

Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus.

Example

Input
  1. 5
    1 2 4 3 3
Output
  1. 4
Input
  1. 8
    2 3 4 4 2 1 3 1
Output
  1. 5

Note

In the first test we can sort the children into four cars like this:

  • the third group (consisting of four children),
  • the fourth group (consisting of three children),
  • the fifth group (consisting of three children),
  • the first and the second group (consisting of one and two children, correspondingly).

There are other ways to sort the groups into four cars.

*/

  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int n;
  7.     int x;
  8.     cin>>n;
  9.     int counter = ;
  10.     int num1 = , num2 = , num3 = ;
  11.     while(n--)
  12.     {
  13.         cin >> x;
  14.         if (x == )
  15.         {
  16.             num1++;
  17.         }
  18.         if (x == )
  19.         {
  20.             num2++;
  21.         }
  22.         if (x == )
  23.         {
  24.             num3++;
  25.         }
  26.         if (x == )
  27.         {
  28.             counter++;
  29.         }
  30.     }
  31.     if (num3 >= num1)
  32.     {
  33.         counter += num3;
  34.         counter += ( (num2 + ) / );//无论 num2 为偶数还是奇数都为(num2 + 1)/ 2
  35.     }
  36.     if (num3 < num1)
  37.     {
  38.         counter += num3;
  39.         num1 = num1 - num3;
  40.         counter += (num2 / );
  41.         num2 = num2 % ;
  42.         if (num2 == )
  43.         {
  44.             counter += (num1 + ) / + ;
  45.         }
  46.         if (num2 == )
  47.         {
  48.             if (num1 > )
  49.             {
  50.                 counter += (num1 - ) / + ;
  51.             }
  52.             if (num1 == )
  53.             {
  54.                 counter = counter + ;
  55.             }
  56.         }
  57.     }
  58.     cout << counter << endl;
  59.     return ;
  60. }

Taxi的更多相关文章

  1. 【HDU1960】Taxi Cab Scheme(最小路径覆盖)

    Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  2. A cost-effective recommender system for taxi drivers

    一个针对出租车司机有效花费的推荐系统 摘要 GPS技术和新形式的城市地理学改变了手机服务的形式.比如说,丰富的出租车GPS轨迹使得出做租车领域有新方法.事实上,最近很多工作是在使用出租车GPS轨迹数据 ...

  3. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  4. [ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]

    Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou ...

  5. zjuoj 3600 Taxi Fare

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3600 Taxi Fare Time Limit: 2 Seconds    ...

  6. Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi

    Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi This spring, Kaggle hosted two competitions w ...

  7. poj 2060 Taxi Cab Scheme (最小路径覆盖)

    http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submi ...

  8. The 9th Zhejiang Provincial Collegiate Programming Contest->Problem A:A - Taxi Fare

    Problem A: Taxi Fare Time Limit: 2 Seconds Memory Limit: 65536 KB Last September, Hangzhou raised th ...

  9. Taxi Cab Scheme POJ && HDU

    Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statistical Charts ...

  10. 二分图最小路径覆盖--poj2060 Taxi Cab Scheme

    Taxi Cab Scheme 时间限制: 1 Sec  内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...

随机推荐

  1. Oracle 未能加载文件或程序集Oracle.DataAccess

    原文地址;https://www.cnblogs.com/xuekai-to-sharp/p/3586071.html 关键是引用DLL:Oracle.DataAccess.dll DLL文件的路径: ...

  2. MongoDB分布式集群搭建

    最近在做一个关于车险的项目,由于数据量较大,实验室的Boss决定采用HBase+ES/MongoDB这两种方案,并做性能对比,本人负责MongoDB方案.为了满足海量数据的存储要求,需要搭建一个分布式 ...

  3. Java happen-before

    下面是happens-before原则规则: 程序次序规则:一个线程内,按照代码顺序,书写在前面的操作先行发生于书写在后面的操作: 锁定规则:一个unLock操作先行发生于后面对同一个锁额lock操作 ...

  4. support:design:26.1.0

    https://blog.csdn.net/qzltqdf3179103/article/details/79583491 compileSdkVersion 26buildToolsVersion ...

  5. eclipce连接数据库增删改查

    1.在mysql中新建一个名为course的数据库,并在其中新建一个course数据表,包含四个字段,id,name,teacher,classname如图(注意:将id设为自动递增,否则后面新增会出 ...

  6. 游戏AI技术 2

    [Unity3D人工智能编程精粹 2] 1.跟随领队行为. 用靠近(Seek)或追逐(Pursuit)实现跟随领队行为并不好.在Seek中,AI角色会被推向领队,最终与领队占据相同位置.而Pursui ...

  7. Bootstrap的aria-label和aria-labelledby

    [Bootstrap的aria-label和aria-labelledby] 用于盲人阅读的属性,基本也没什么用. 参考:http://blog.csdn.net/liuyan19891230/art ...

  8. Beef的使用

    应用普遍转移到B/S架构,浏览器成为统一客户端程序 通过注入JS脚本,利用浏览器攻击其他网站 ruby编写 攻击手段 利用网站XSS漏洞实现攻击 诱使客户端访问含有hook的伪造站点 结合中间人攻击注 ...

  9. The <classpath> or <modulepath> for <junit> must include junit.jar if not in Ant's own classpath

    The <classpath> or <modulepath> for <junit> must include junit.jar if not in Ant's ...

  10. SML + NL + HJ

    Join是一种试图将两个表结合在一起的谓词,一次只能连接2个表,表连接也可以被称为表关联.在后面的叙述中,我们将会使用”row source”来代替”表”,因为使用row source更严谨一些,并且 ...