Codeforces 899 A.Splitting in Teams
1 second
256 megabytes
standard input
standard output
There were n groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team.
The first line contains single integer n (2 ≤ n ≤ 2·105) — the number of groups.
The second line contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 2), where ai is the number of people in group i.
Print the maximum number of teams of three people the coach can form.
4
1 1 2 1
1
2
2 2
0
7
2 2 2 1 1 1 1
3
3
1 1 1
1
In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) and the seventh group (of one person),
- The second group (of two people) and the sixth group (of one person),
- The third group (of two people) and the fourth group (of one person).
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
int n;
while(~scanf("%d",&n)){
int num1=,num2=;
for(int i=;i<n;i++){
int x;
scanf("%d",&x);
if(x==)num1++;
else num2++;
}
if(num2>num1)cout<<num1<<endl;
else cout<<num2+(num1-num2)/<<endl;
}
return ;
}
Codeforces 899 A.Splitting in Teams的更多相关文章
- Codeforces Round #452 (Div. 2)-899A.Splitting in Teams 899B.Months and Years 899C.Dividing the numbers(规律题)
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input standar ...
- CF899A Splitting in Teams
CF899A Splitting in Teams 题意翻译 n个数,只有1,2,把它们任意分组,和为3的组最多多少 题目描述 There were nn groups of students whi ...
- 【Codeforces Round #452 (Div. 2) A】 Splitting in Teams
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bi ...
- CodeForces Round #527 (Div3) B. Teams Forming
http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...
- Codeforces 872C Maximum splitting:数学【分解成合数之和】
题目链接:http://codeforces.com/contest/872/problem/C 题意: 给你一个数n,问你最多能将n分解成多少个合数之和.(若不能分解,输出-1) 题解: 若要让合数 ...
- 【CodeForces 297C】Splitting the Uniqueness
题意 序列s有n个数,每个数都是不同的,把它每个数分成两个数,组成两个序列a和b,使ab序列各自去掉个数后各自的其它数字都不同. 如果存在一个划分,就输出YES,并且输出两个序列,否则输出NO. 分析 ...
- Codeforces 899 F. Letters Removing (二分、树状数组)
题目链接:Letters Removing 题意: 给你一个长度为n的字符串,给出m次操作.每次操作给出一个l,r和一个字符c,要求删除字符串l到r之间所有的c. 题解: 看样例可以看出,这题最大的难 ...
- Codeforces 870C Maximum splitting (贪心+找规律)
<题目链接> 题目大意: 给定数字n,让你将其分成合数相加的形式,问你最多能够将其分成几个合数相加. 解题分析: 因为要将其分成合数相加的个数最多,所以自然是尽可能地将其分成尽可能小的合数 ...
- Codeforces 899 C.Dividing the numbers-规律
C. Dividing the numbers time limit per test 1 second memory limit per test 256 megabytes input s ...
随机推荐
- Computer HDU - 2196
Computer HDU - 2196 A school bought the first computer some time ago(so this computer's id is 1). Du ...
- vector函数用法
vector是线性容器,它的元素严格的按照线性序列排序,和动态数组很相似,和数组一样,它的元素存储在一块连续的存储空间中,这也意味着我们不仅可以使用迭代器(iterator)访问元素,还可以使用指针的 ...
- Sublime Text配置python以及快捷键总结
1.打开Tools > Build System > New Build System.. 2.点击New Build System后,会生成一个空配置文件,在这个配置文件内覆盖配置信息, ...
- Git-Git初始化
创建版本库及第一次提交 通过如下操作来查看一下您的Git版本. $ git --version git version 1.7.4 在开始 Git 之旅之前,我们需要设置一下 Git 的配置变量,这是 ...
- sql:where中多种状况简便写法
字段名:Bran,block,are ,store 四个字段中存在值等于0或者不等于0,两种情况.where中如果用if等条件判断会有16中组合,如果采用where中的条件就避免了这个情况. decl ...
- python项目中输出指定颜色的日志
起因 在开发项目过程中,为了方便调试代码,经常会向stdout中输出一些日志,默认的这些日志就直接显示在了终端中.而一般的应用服务器,第三方库,甚至服务器的一些通告也会在终端中显示,这样就搅乱了我们想 ...
- Contest1893 - 2019年6月多校联训b层测试1
传送门 密码:waxadyt T1 暴力 对于任意相邻的两个值 中间能到达的最大高度是固定的 加上头尾,判一下就好了 代码//感谢Th Au K #include<bits/stdc++.h&g ...
- js 实现5秒倒计时后跳转页面
<script type="text/javascript"> function countDown(secs, surl) { var jumpTo = docume ...
- SpringMVC基本概念
DispatcherServlet:MVC的前端控制器,浏览器用户的请求经过DispatcherServlet的分发,到达合适的controller,生产业务数据所需要的model,model通过Di ...
- libcmt.lib和msvcrt.lib冲突,原因和解决方法
libcmt.lib和msvcrt.lib冲突,原因和解决方法 https://blog.csdn.net/longlijun/article/details/7331093 libcmt.lib是w ...