CF899A Splitting in Teams

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.

输入输出样例

输入样例#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=1;i<=n;i++){
            int x;scanf("%d",&x);
            if(x==1)    sum1++;
            if(x==2)    sum2++;
        }
        ans+=min(sum1,sum2);sum1-=ans,sum2-=ans;
        ans+=sum1/3;
        cout<<ans;
    }

原文地址:https://www.cnblogs.com/cangT-Tlan/p/8440816.html

时间: 2024-08-27 20:17:10

CF899A Splitting in Teams的相关文章

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

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 贪心 1优先和2组队. 如果1没有了 就结束. 如果1还有多余的. 那么就自己3个3个组队 [代码] #include <bits/stdc++.h> using namespace std; const int N = 2e5; int n; int a[3]; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.txt", "r", st

Teams(uva11609+组合)

I - Teams Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVA 11609 题意:有n个人,选多个人参加比赛,其中一个是队长,队长不同其他选手相同也算作不同的方案,.问你一共有多少种方案. 思路:自己才纸上稍微推理一下,n*2n-1%mod: 转载请注明出处:寻找&星空の孩子 题目链接:UVA 11609 也欢迎来我开的专题刷题.哈哈htt

&quot;is not on any development teams &quot; Xcode的账号错误问题

"***@*** is not on any development teams " Xcode现在在"Accounts"中时不时会出现这个提示. 但其他按钮都是灰色的, 也没有"确定" "刷新"按钮, 实在无奈. 解决方法: 1:进入 "Organizer"页面, 选 "Archives", 2:随便找一个你的archives包, 3:选择右边的Validate, 这时会验证你的开发者

uva10911 - Forming Quiz Teams(记忆化搜索)

题目:uva10911 - Forming Quiz Teams(记忆化搜索) 题目大意:给出N对点的坐标,然后将这2 * N个点分组,Xi代表第i组的点之间的距离,求sum(Xi)最小值. 解题思路:这里的点最多16个,如果暴力求解的话16!,会超时的.这里的点取和不取可以用0和1表示,这样的话所有的状态可以用二进制数X来表示.dp[X]  = Min (dp[newx] + d[i][j]):记录下状态来减少不必要的重复操作. i .j代表点的下标,这些点必须是X状态下没取过的,newx就是

10317 Fans of Footbal Teams

10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description Two famous football teams, named AC Milan(AC米兰) and Inter Milan(国际米兰) will have a match in GuangZhou City, which is exciting. So a lot of fans get tog

CodeForces 432A Choosing Teams(水)

Description The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC r

[Webpack 2] Maintain sane file sizes with webpack code splitting

As a Single Page Application grows in size, the size of the payload can become a real problem for performance. In this lesson, learn how to leverage code splitting to easily implement lazy loading for your application to load only the code necessary

10317 Fans of Footbal Teams(并查集)

10317 Fans of Footbal Teams 时间限制:1000MS  内存限制:65535K提交次数:0 通过次数:0 题型: 编程题   语言: G++;GCC Description Two famous football teams, named AC Milan(AC米兰) and Inter Milan(国际米兰) will have a match in GuangZhou City, which is exciting. So a lot of fans get tog

Codeforces Round #273 (Div. 2) B . Random Teams 贪心

B. Random Teams n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends. Your task is to write a progra