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 ...
随机推荐
- python-01 spider原理
用Python可以做什么?可以做日常任务,比如自动备份你的MP3:可以做网站,很多著名的网站包括YouTube就是Python写的:可以做网络游戏的后台,很多在线游戏的后台都是Python开发的.总之 ...
- 03015_JSTL技术
1.JSTL概述 (1)JSP(JSP Standard Tap Library),JSP标准标签库,可以嵌入在jsp页面中使用标签的形式完成业务逻辑等功能.jstl出现的目的同el一样也是要替代js ...
- 自动检测ARouter路由地址分组使用冲突问题
背景 项目中使用ARouter进行路由,由于不同上层业务模块都可能会使用到同一目标的路由地址,因此,将所有业务模块的路由地址以一种类似静态常量的方式设置在Base模块中.这样,在实际目前上加上对应此地 ...
- Python基础-week01 Python安装/变量/输入/及循环语句使用
一.Python介绍 (1).目前Python主要应用领域: 云计算: 云计算最火的语言, 典型应用OpenStack WEB开发: 众多优秀的WEB框架,众多大型网站均为Python开发,You ...
- 【LeetCode】Remove Duplicates from Sorted List(删除排序链表中的重复元素)
这道题是LeetCode里的第83道题. 题目描述: 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次. 示例 1: 输入: 1->1->2 输出: 1->2 示例 2: ...
- Halcon11 Linux 下载
Halcon11 Linux下载地址:http://www.211xun.com/download_page_3.html HALCON 11 是一套机器视觉图像处理库,由一千多个算子以及底层的数据管 ...
- [oldboy-django][2深入django]后台生成form标签并设置标签的属性
# Form生成html标签 a. 通过Form生成Input输入框,Form标签,以及submit标签还是要在前端写的, 但是Form标签内的Input标签可以在后台实现:只需要按以下步骤 - vi ...
- JS判断是否是IE浏览器的几种方式
1.得到浏览器的信息,返回由客户机发送服务器的 user-agent 头部的值. if(navigator.userAgent.indexOf("MSIE 8.0")>0){ ...
- 【转】log4js在PM2的cluster模式下大坑
请直接查看原文:https://blog.yourtion.com/fix-log4js-with-pm2-not-work.html 之前一直使用 debug 还有 console.log 去打日志 ...
- BZOJ 1015:[JSOI2008]星球大战starwar(逆向处理+并查集)
[JSOI2008]星球大战starwar 时间限制: 3 Sec 内存限制: 162 MB[题目描述] ...