题意翻译

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. vim插件系列

    http://foocoder.com/blog/mei-ri-vimcha-jian-ping-hua-gun-dong-accelerated-smooth-scroll-dot-vim.html ...

  2. How do you install Google Chrome on Ubuntu?

    https://askubuntu.com/questions/510056/how-to-install-google-chrome sudo apt-get install chromium-br ...

  3. 饭卡(hdoj--2546--背包)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  4. js中的面向对象(一)封装

    1.简单的封装(定义) var cat1 = {}; cat1.name = '阿黄'; cat1.sex = '男'; cat1.age = 11; //cat2也同样具有三个属性 var cat2 ...

  5. redis实现计数--------Redis increment

    经理提出新的需求,需要知道每天微信推送了多少条模板消息,成功多少条,失败多少条,想到用Redis缓存,网上查了一些资料,Redis中有方法increment,测试代码如下 Controller imp ...

  6. WPF 漏斗控件 等待沙漏效果

    由于WPF中不支持gif图片因此要实现一个漏斗沙漏效果有点小麻烦. 网上有一款开源的控件 理论上完全开源 官网 http://wpfspark.codeplex.com/贴一下效果图 大家感觉需要就在 ...

  7. 使用vs2017创建项目并添加到git中

    参考 https://blog.csdn.net/qq373591361/article/details/71194651 https://blog.csdn.net/boonya/article/d ...

  8. 目录处理文件&链接命令

    一.目录处理文件 1.删除文件或目录 rm -rf [文件或目录]           //remove:删除文件或目录  -r:删除目录  -f:强制 2.复制文件或目录 cp [选项] [原文件或 ...

  9. Mysql优化-为表字段添加索引

    1.添加PRIMARY KEY(主键索引): ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` ) 2.添加UNIQUE(唯一索引) : ALTE ...

  10. 函数编程中functor和monad的形象解释

    函数编程中functor和monad的形象解释 函数编程中Functor函子与Monad是比较难理解的概念,本文使用了形象的图片方式解释了这两个概念,容易理解与学习,分别使用Haskell和Swift ...