CF899A Splitting in Teams
题意翻译
n个数,只有1,2,把它们任意分组,和为3的组最多多少
题目描述
There were nn 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 nn ( 2<=n<=2·10^{5}2<=n<=2⋅105 ) — the number of groups.
The second line contains a sequence of integers a_{1},a_{2},...,a_{n}a1,a2,...,an ( 1<=a_{i}<=21<=ai<=2 ), where a_{i}ai is the number of people in group ii .
输出格式:
Print the maximum number of teams of three people the coach can form.
输入输出样例
说明
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<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,ans,sum1,sum2;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
int x;scanf("%d",&x);
if(x==) sum1++;
if(x==) sum2++;
}
ans+=min(sum1,sum2);sum1-=ans,sum2-=ans;
ans+=sum1/;
cout<<ans;
}
CF899A 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 ...
- Codeforces 899 A.Splitting in Teams
A. Splitting in Teams time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 【Codeforces Round #452 (Div. 2) A】 Splitting in Teams
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bi ...
- Codeforces Round #451 & Codeforces Round #452
Rounding Solution Proper Nutrition 枚举 Solution Phone Numbers 模拟 Solution Alarm Clock 贪心,好像不用线段树也可以,事 ...
- Codeforces Round #452 (Div. 2) A B C
Codeforces Round #452 (Div. 2) A Splitting in Teams 题目链接: http://codeforces.com/contest/899/problem/ ...
- Educational Codeforces Round 9 B. Alice, Bob, Two Teams 前缀和
B. Alice, Bob, Two Teams 题目连接: http://www.codeforces.com/contest/632/problem/B Description Alice and ...
- codeforces 632B B. Alice, Bob, Two Teams(暴力)
B. Alice, Bob, Two Teams time limit per test 1.5 seconds memory limit per test 256 megabytes input s ...
- 关于 Word Splitting 和 IFS 的三个细节
在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...
- Rnadom Teams
Rnadom Teams 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.actioncid=88890#problem/B 题目: Descript ...
随机推荐
- 关于jetty服务器默认首页和端口设置
一.jetty服务器部署.启动成功后,在浏览器输入http://localhost:8080/ 可以直接访问到jetty欢迎首页. 这是因为在Jetty包中默认带了一个test.war的应用,在${J ...
- 在Android系统中修改Android.mk使其同时编译rgb2565和rgb2888(向out/host/linux-x86/bin/下新增加一个工具命令)【转】
本文转载自:http://blog.csdn.net/mu0206mu/article/details/7514559 在Android系统中修改android.mk使其同时编译rgb2565和rgb ...
- c#为程序添加全局热键的方法
在程序失去焦点或者在后台运行时,可以通过使用全局热键的方式,进行一些快捷的操作,如QQ默认操作中ctrl+alt+A调出截图功能. 在Windows中实现热键功能需要使用win32的Api函数Regi ...
- Delete, drop table, truncate之间的区别
Delete, drop table, truncate有什么区别? delete 删除表中数据,可以删除一条或多条记录,可以回滚,记录操作日记,是DML truncate table,一次性清空表中 ...
- 3.TinkPHP中的模型
1.配置数据库的连接设置 数据库的连接配置项可以在系统的主配置文件中 2.什么是模型? 模型是MVC 三大组成部分的M,作用是负责与数据表达额交互(CRUD) 3.模型的创建 命名规范:不带前缀的标明 ...
- 给WordPress的TinyMCE Advanced编辑器加上中文字体
为TinyMCE编辑器增加中文字体并不复杂,只需要将将如下代码加到当前主题的functions.php文件中最后一个?>的前面即可: 不要忘记保存,然后更新一遍浏览器即可 //为TinyMCE编 ...
- Django[pronounced dʒ] installation on windows
1.Install python, download python windows installer from http://www.python.org/download/ and do inst ...
- levelDB数据库使用及实例 - 高性能nosql存储数据库
LevelDB是google公司开发出来的一款 超高性能kv存储引擎,以其惊人的读性能和更加惊人的写性能在轻量级nosql数据库中鹤立鸡群. 此开源项目目前是支持处理十亿级别规模Key-Value型数 ...
- java 简单工厂模式实现
简单工厂模式:也可以叫做静态工厂方法,属于类创建型模式,根据不同的参数,返回不同的类实现. 主要包含了三个角色: A.抽象产品角色 一般用接口 或是 抽象类实现 B.具体的产品角色,具体的类的实现 C ...
- CBIR--Survey.C/GPU优化.Sys搭建
一:CBIR综述:转自于wiki:http://zh.wikipedia.org/wiki/CBIR 参考链接:http://blog.csdn.net/kezunhai/article/detail ...