题意翻译

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.

输入输出样例

输入样例#1: 复制

4
1 1 2 1
输出样例#1: 复制

1
输入样例#2: 复制

2
2 2
输出样例#2: 复制

0
输入样例#3: 复制

7
2 2 2 1 1 1 1
输出样例#3: 复制

3
输入样例#4: 复制

3
1 1 1
输出样例#4: 复制

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<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的更多相关文章

  1. 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 ...

  2. Codeforces 899 A.Splitting in Teams

      A. Splitting in Teams   time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. 【Codeforces Round #452 (Div. 2) A】 Splitting in Teams

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bi ...

  4. Codeforces Round #451 & Codeforces Round #452

    Rounding Solution Proper Nutrition 枚举 Solution Phone Numbers 模拟 Solution Alarm Clock 贪心,好像不用线段树也可以,事 ...

  5. Codeforces Round #452 (Div. 2) A B C

    Codeforces Round #452 (Div. 2) A Splitting in Teams 题目链接: http://codeforces.com/contest/899/problem/ ...

  6. 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 ...

  7. 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 ...

  8. 关于 Word Splitting 和 IFS 的三个细节

    在 Bash manual 里叫 Word Splitting,在 Posix 规范里叫 Field Splitting,这两者指的是同一个东西,我把它翻译成“分词”,下面我就说三点很多人都忽略掉(或 ...

  9. Rnadom Teams

    Rnadom  Teams 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.actioncid=88890#problem/B 题目: Descript ...

随机推荐

  1. iOS 隐藏NavigationBar的方法

    使用下面方法: - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.navigationCon ...

  2. Android 删除新版安卓fragment_main.xml

    在新版本号的ADT中,创建androidproject时默认会产生两个xml文件--fragment_main和activity_main. 个人建议把fragment_main这个文件删除掉 1)将 ...

  3. Oracle 11gR2 List-Range分区实验

    一.实验目的 採用List-Range分区,对主分区指定表空间或者对子分区指定表空的不同情况,測试例如以下内容: 1.对List主分区不指定表空间.对Range子分区指定表空间,数据实际存储在哪个表空 ...

  4. 2016.04.07,英语,《Vocabulary Builder》Unit 11

    cant, from the Latin verbs canere and cantare, meaning 'sing'. by way of French, add an h to the roo ...

  5. mysql查询orderby

    --按某一字段分组取最大(小)值所在行的数据 /* 数据如下: name val memo a    2   a2(a的第二个值) a    1   a1--a的第一个值 a    3   a3:a的 ...

  6. css中!important的用法

    {*rule !important}这个css规则当今在网页制作的时候的普及已经非常流行了,以前我对它的理解就停留在‘浏览器是否识别阶段’ 而没有真正去研究过,可是现在发生了变化.众所周知,!impo ...

  7. anaconda 使用 及 tensorflow-gpu 安装

    Anaconda简易使用 创建新环境 conda create -n rcnn python=3.6 删除环境 conda remove -n rcnn --all 进入环境 conda activa ...

  8. Email非正则表达式的判断

    判断一个邮件是否合法,我们除了可以使用正则表达四以外还可以利用,Email地址的规律进行判断,那么一个合法的Email有哪些要求昵?具体如下: 必须有@与. @必须在第一个.之前 @与.不能连在一起 ...

  9. E - Dividing Orange

    Problem description One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments ...

  10. 字符串比较——compareTo函数

    package com.day03.ifelse; import java.math.BigInteger; /** * @author 王恒 * @datetime 2017年4月7日 下午3:13 ...