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 ...
随机推荐
- 兴趣点 / 关键点( Interest point/Keypoint )
• 不同视角图片之间的映射 • 稳定局部特征点 • 可重复性.显著性 • 抗图片变换 • 外貌变换(亮度.光照) ...
- Appium appium 安装不了
npm --registry http://registry.cnpmjs.org install -g appium使用npm的国内镜像可以安装,速度很不错.以后不想输入ip的话可以输入以下命令:n ...
- IE 兼容background-size
1:修改src *background-size: cover;//兼容ie的background-size filter: progid:DXImageTransform.Microsoft.Alp ...
- 11.14java课堂测试
源代码: import java.*; import java.util.*; import java.io.File; import java.io.FileInputStream; import ...
- IDEA配置 gradle
下载解压自己需要的gradle版本:https://gradle.org/releases/(免安装) 配置环境变量 打开命令窗口,输入 gradle -v IDEA配置gradle:file-&g ...
- hello world讲解1
1. HelloWorld程序解析---------------------------------------------------------------------------------- ...
- web 浏览器窗口
1.窗口位置: 取得浏览器窗口左边和上边距屏幕左边和上边的位置 var leftPos = (typeof window.screenLeft == "number")? wind ...
- GreaseMonkey开发(一):第一个自定义插件Hello GreaseMonkey!
GreaseMonkey最好在火狐浏览器上使用,下载好GreaseMonkey,重启浏览器右上角会出现一只小猴子. 新建一个脚本. 确定,填入代码保存. // ==UserScript== // @n ...
- 算法之LOWB三人组之选择排序
选择排序 思想是在一个列表中每次循环一遍,拿到最小值,接着再从剩下的无序区中继续拿最小值,如此循环,直到结束. 时间复杂度为O(n^2) # 最简单的一个选择排序,循环一个列表,拿到最小值,添加到一个 ...
- pta l2-8(最长对称字串)
题目链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805067704549376 题意:求给定字符串的最长回文串的长 ...