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 ...
随机推荐
- php学习随记3
<? php #正則表達式 #就是一种描写叙述字符串结构的语法规则 #是一个特定的格式化模式 #1. 行定位符 /* 1) ^行首 2)$行尾 tm eqaul Tomorrow Moon ^t ...
- windows下mysql5.6.20使用mysqldumpslow.pl分析慢日志
要想执行mysqldumpslow.pl(这是perl程序),下载perl编译器. 下载地址:http://pan.baidu.com/s/1i3GLKAp 就是ActivePerl_5.16.2.3 ...
- wpf datagridtemplatecolumn visibility binding
因为datagridtemplatecolumn不在Virsual Tree中,不能继承DataGrid的DataContext, 所以想要绑定到datagridtemplatecolumn的 vis ...
- Java编程:切面条
/* 一根高筋拉面,中间切一刀,能够得到2根面条. 假设先对折1次.中间切一刀.能够得到3根面条. 假设连续对折2次,中间切一刀.能够得到5根面条. 那么.连续对折10次.中间切一刀.会得到多少面条呢 ...
- Java:笔记-1
ylbtech-Java:笔记-1 1.返回顶部 1. /** * 简介请求 * @return */ @RequestMapping("/JJ") public String j ...
- php---依赖倒转(反转控制)原则
一.简介 依赖注入和控制反转说的实际上是同一个东西,它们是一种设计模式,这种设计模式用来减少程序间的耦合 优点:使用依赖注入,最重要的一点好处就是有效的分离了对象和它所需要的外部资源,使得它们松散耦合 ...
- python 网络通讯 服务器端代码demo,能够同时处理多个客户端的连接请求
这是一个python网络通讯服务器端的代码demo,能够同时处理多个客户端的连接请求. from socket import * import threading from datetime impo ...
- 如何修改 WordPress 数据库前缀
我们知道 WordPress 的数据库表,可以设置前缀,默认是 wp_,很多同学也就默认用了 wp_,如果某种原因(比如提高安全性)要修改的 WordPress 数据的前缀,我们应该怎么做? 开始之前 ...
- 管窥python语法
刚接触python,mark下所见所得: 1.Python调用底层API,可在任何platform上运行,包括Windows.Mac.Unix: 2.用#符号对代码或语句进行注释,#后的代码不被编译: ...
- 【Oracle】修改参数的同时添加注释
当修改参数时添加注释,我们会用到如下语句: alter system set parameter=value comment='description'; --修改参数需要有相应权限的用户去执行. 例 ...