题意翻译

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. PHP独立操作符

    & 与 ^ 位逻辑异或 $ # ! 逻辑或 ~  按位取反

  2. 2016.04.11,英语,《Vocabulary Builder》Unit 12

    umbr, from the Latin umbra, 'shadow', umbrella, -ella, 'little', means 'little shadow'. adumbrate: [ ...

  3. 日积(Running)月累(ZSSURE):Task之Cancel、OpenAccess之Delete及fo-dicom之DeepCopy、

    题记: 最近看了一篇关于架构方面的良心长文你的架构是怎样一步步腐化的?,文中字字句句道出了诸多从业者.初创企业,以及BAT都会遇到的问题,细细品读后认为工作生活中的诸多情况皆如此,都会有一个体量由小到 ...

  4. eclipse中打字中文突然变成繁体

    eclipse中打字中文突然变成繁体 在用eclipse做android项目的时候,发现打出来的字全部是繁体,而且QQ等其他位置又是简体. 原因:eclipse的快捷点ctrl+alt+f(forma ...

  5. friend(hdoj 1719)

    Friend Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. Node.js:函数

    ylbtech-Node.js:函数 1.返回顶部 1. Node.js 函数 在JavaScript中,一个函数可以作为另一个函数的参数.我们可以先定义一个函数,然后传递,也可以在传递参数的地方直接 ...

  7. shp系列(四)——利用C++进行Shx文件的读(打开)

    1.shx文件的基本情况 shx文件又叫索引文件,主要包含坐标文件的索引信息,文件中每个记录包含对应的坐标文件记录距离坐标文件的初始位置的偏移量.通过索引文件可以很方便地在坐标文件中定位到指定目标的坐 ...

  8. php对文件/目录操作的基础知识(图解)

    具体的如下图所示:

  9. Hadoop MapReduce编程 API入门系列之MapReduce多种输出格式分析(十九)

    不多说,直接上代码. 假如这里有一份邮箱数据文件,我们期望统计邮箱出现次数并按照邮箱的类别,将这些邮箱分别输出到不同文件路径下. 代码版本1 package zhouls.bigdata.myMapR ...

  10. Npgsql使用入门(三)【批量导入数据】

    Program.cs代码: class Program { static void Main(string[] args) { var test = new PgBulkCopyHelper<S ...