题意翻译

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. H3C子接口配置要点及实例说明

     类型一:以太网子接口配置要点(单臂路由)  第一步:在路由器对端的交换机上配置好vlan信息(如vlan10/vlan20)  第二步:将交换机上与路由器直接相连的以太口配置成trunk口并同意 ...

  2. udev的使用-minicom没有权限打开串口,更改 ttyUSB0 的权限

    udev的使用-minicom没有权限打开串口,更改 ttyUSB0 的权限 使用minicom打开串口会提示没有权限,必需要用 sudo,怎样更改串口设备的权限能够让普通用户读写呢? 事实上仅仅要更 ...

  3. RDLC报表钻取空白页问题

    在改动报表查询条件时,钻取页突然空白了,百思不得其解,之前好好的,研究了一个下午和一个晚上.查资料等等,网上非常多资料都是设置报表的 ConsumeConteinerWhitespace = True ...

  4. oc11---结构体作为属性

    // // main.m // 结构体作为对象的属性 #import <Foundation/Foundation.h> typedef struct { int year; int mo ...

  5. Hdu-5992 2016ACM/ICPC亚洲区青岛站 K.Finding Hotels KDtree

    题面 题意:二维平面上有很多点,每个点有个权值,现在给你一个点(很多组),权值v,让你找到权值小于等于v的点中离这个点最近的,相同的输出id小的 题解:很裸的KDtree,但是查询的时候有2个小限制, ...

  6. POJ3087 Shuffle'm Up

    题目: 现有字符串s1.s2.s12,其中s1.s2的长度为len,s12的长度为2*len. 是否可以通过一些操作使s1和s2转换合并成s12? 变换的操作规则如下: 假设s1=11111,s2=0 ...

  7. SwiftUI 官方教程(三)

    3. 用 Stacks 组合 View 在上一节创建标题 view 后,我们来添加 text view,它用来显示地标的详细信息,比如公园的名称和所在的州. 在创建 SwiftUI view 时,我们 ...

  8. WPF Menu控件自定义Style

       自定义WPF中Menu控件的样式

  9. 【转】PowerDesigner物理数据表生成C#实体类Model

    model实体类是什么: 在三层架构UI,BLL,DAL中,有时用户插入一条记录到数据库中,必然会有不少数据,按正常编程,也必然会一下子调用某个函数传入不少参数.为了减少参数的数量,达到高效简洁的效果 ...

  10. Android网络编程随想录(四)

    前面三篇文章从最基础的TCP,HTTP协议理论开始,然后介绍了在Android的开发中所使用的HttpClient和HttpUrlConnection这两种Http客户端.在本文中,我们一起来学习一下 ...