Taxi
/*
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
5
1 2 4 3 3
4
8
2 3 4 4 2 1 3 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.
*/
#include <iostream> using namespace std; int main() {
int n;
int x;
cin>>n;
int counter = ;
int num1 = , num2 = , num3 = ;
while(n--)
{
cin >> x;
if (x == )
{
num1++;
}
if (x == )
{
num2++;
}
if (x == )
{
num3++;
}
if (x == )
{
counter++;
}
}
if (num3 >= num1)
{
counter += num3;
counter += ( (num2 + ) / );//无论 num2 为偶数还是奇数都为(num2 + 1)/ 2
}
if (num3 < num1)
{
counter += num3;
num1 = num1 - num3;
counter += (num2 / );
num2 = num2 % ;
if (num2 == )
{
counter += (num1 + ) / + ;
}
if (num2 == )
{
if (num1 > )
{
counter += (num1 - ) / + ;
}
if (num1 == )
{
counter = counter + ;
}
}
}
cout << counter << endl;
return ;
}
Taxi的更多相关文章
- 【HDU1960】Taxi Cab Scheme(最小路径覆盖)
Taxi Cab Scheme Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- A cost-effective recommender system for taxi drivers
一个针对出租车司机有效花费的推荐系统 摘要 GPS技术和新形式的城市地理学改变了手机服务的形式.比如说,丰富的出租车GPS轨迹使得出做租车领域有新方法.事实上,最近很多工作是在使用出租车GPS轨迹数据 ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- [ACM_数学] Taxi Fare [新旧出租车费差 水 分段函数]
Description Last September, Hangzhou raised the taxi fares. The original flag-down fare in Hangzhou ...
- zjuoj 3600 Taxi Fare
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3600 Taxi Fare Time Limit: 2 Seconds ...
- Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi
Taxi Trip Time Winners' Interview: 3rd place, BlueTaxi This spring, Kaggle hosted two competitions w ...
- poj 2060 Taxi Cab Scheme (最小路径覆盖)
http://poj.org/problem?id=2060 Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submi ...
- 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 ...
- Taxi Cab Scheme POJ && HDU
Online Judge Problem Set Authors Online Contests User Web Board Home Page F.A.Qs Statistical Charts ...
- 二分图最小路径覆盖--poj2060 Taxi Cab Scheme
Taxi Cab Scheme 时间限制: 1 Sec 内存限制: 64 MB 题目描述 Running a taxi station is not all that simple. Apart f ...
随机推荐
- 使用tf.print()打印tensor内容
使用tf.Print()打印tensor内容,这是tensorflow中调试bug的一个手段,例子如下所示: import tensorflow as tf a = tf.Variable(tf.ra ...
- jenkins gradle 实践总结
执行protoc 通过shell ,那么将gradle 中的proto 项目移除即可 安装 最新的idea 版本 ,并安装 最新kotlin 插件,通过http://plugins.jetbrains ...
- 1.3.4、CDH 搭建Hadoop在安装之前(端口---Impala使用的端口)
Impala使用的端口 Impala使用下表中列出的TCP端口.在部署Impala之前,请确保在每个系统上打开这些端口. Component Service Port Access Requireme ...
- Gimbal Lock
[Gimbal Lock] 万向锁源于欧拉角的是有序处理的.U3D中的序列为: y->x->z.当旋转y时,local坐标系与世界坐标系重合,所以y等于永远按惯性坐标旋转.当x旋转+/-9 ...
- Unity&UGUI
UI:User Interface 用户交互接口,处理用户与程序直接的交互 新建一个UI控件,都会同时新建两个物体: --Canvas:画布,所有的UI控件都必须放到画布上 --EnventSyste ...
- Android学习路-Android Studio的工程目录
说明:下图为一个app的工程目录,如果在res下随便建立文件夹(比如test等名字)是不会显示在工程内的
- 调试JS代码的神器
1.火狐浏览器的 “Web开发者” 可以打断点,实时查看当前值 2.谷歌浏览器的“开发者工具” 可以打断点,实时查看当前值
- pyinstaller linux系统下打包python源文件
将python程序放在其他linux服务器中执行,通常linux服务器中默认安装python2.6,很多情况下需要升级为2.7 且要安装程序中需要的第三方模块,配置较为麻烦,所以通过在本地linux ...
- RocketMQ-quickstart(批量消费)
一.专业术语 Producer 消费生产者,负责产生消息,一般由业务系统负责产生消息 Consumer 消息消费者,负责消费消息,一般是后台系统负责异步消费 Push Consumer Consume ...
- Anaconda常用命令大全
使用conda 首先我们将要确认你已经安装好了conda 配置环境 下一步我们将通过创建几个环境来展示conda的环境管理功能.使你更加轻松的了解关于环境的一切.我们将学习如何确认你在哪个环境中,以及 ...