链接:

https://codeforces.com/contest/1176/problem/B

题意:

You are given an array a consisting of n integers a1,a2,…,an.

In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array [2,1,4] you can obtain the following arrays: [3,4], [1,6] and [2,5].

Your task is to find the maximum possible number of elements divisible by 3 that are in the array after performing this operation an arbitrary (possibly, zero) number of times.

You have to answer t independent queries.

思路:

找除三的余数,优先配对1和2.

再3个1或3个2可以配成一个。

代码:

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MAXN = 1e2 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t; int a[3]; int main()
{
scanf("%d", &t);
while (t--)
{
memset(a, 0, sizeof(a));
scanf("%d", &n);
int v;
for (int i = 1;i <= n;i++)
{
scanf("%d", &v);
a[v%3]++;
}
if (a[1] > a[2])
swap(a[1], a[2]);
int res = a[0]+a[1]+(a[2]-a[1])/3;
cout << res << endl;
} return 0;
}

Codeforces Round #565 (Div. 3) B. Merge it!的更多相关文章

  1. Codeforces Round #565 (Div. 3) B

    B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...

  2. Codeforces Round #565 (Div. 3) A. Divide it!

    链接: https://codeforces.com/contest/1176/problem/A 题意: You are given an integer n. You can perform an ...

  3. Codeforces Round #565 (Div. 3) C. Lose it!

    链接: https://codeforces.com/contest/1176/problem/C 题意: You are given an array a consisting of n integ ...

  4. Codeforces Round #565 (Div. 3) A

    A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...

  5. Codeforces Round #565 (Div. 3) F.Destroy it!

    题目地址:http://codeforces.com/contest/1176/problem/F 思路:其实就是一个01背包问题,只是添加了回合和每回合的01限制,和每当已用牌数到了10的倍数,那张 ...

  6. Codeforces Round #565 (Div. 3)

    传送门 A. Divide it! •题意 给定一个数n, 每次可以进行下列一种操作 1.如果n可以被2整除,用n/2代替n 2.如果n可以被3整除,用2n/3代替n 3.如果n可以被5整除,用4n/ ...

  7. Codeforces Round #565 (Div. 3)--D. Recover it!--思维+欧拉筛

    D. Recover it! Authors guessed an array aa consisting of nn integers; each integer is not less than ...

  8. Codeforces Round #565 (Div. 3) C. Lose it! (思维)

    题意:给你一串只含\(4,8,15,16,23,42\)的序列,如果它满足长度是\(6\)的倍数并且有\(\frac {k}{6}\)个子序列是\([4,8,15,16,23,42]\),则定义它是好 ...

  9. Codeforces Round #446 (Div. 2)

    Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...

随机推荐

  1. BZOJ5461: [PKUWC2018]Minimax

    BZOJ5461: [PKUWC2018]Minimax https://lydsy.com/JudgeOnline/problem.php?id=5461 分析: 写出\(dp\)式子:$ f[x] ...

  2. NOIP 2011 DAY 2

    第一题:计算系数 题目 给定一个多项式 (ax+by)k​​,请求出多项式展开后x​​ny​m​​ 项的系数. 输入 共一行,包含 5 个整数,分别为 a,b,k,n,m,每两个整数之间用一个空格隔开 ...

  3. ACM学习历程—HDU1695 GCD(容斥原理 || 莫比乌斯)

    Description Given 5 integers: a, b, c, d, k, you're to find x in a...b, y in c...d that GCD(x, y) = ...

  4. Poj1163 The Triangle(动态规划求最大权值的路径)

    一.Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a pro ...

  5. 【转】 Pro Android学习笔记(二一):用户界面和控制(9):Gallery和SimpleAdapter

    Gallery画廊式控件,如图所示,但是在API level 16,也即Android 4.1,被deprecated,可以使用HorizontableScroolView和ViewPager.但是后 ...

  6. 数据库:mysql 获取刚插入行id[转]

    我们在写数据库程序的时候,经常会需要获取某个表中的最大序号数, 一般情况下获取刚插入的数据的id,使用select max(id) from table 是可以的.但在多线程情况下,就不行了. 下面介 ...

  7. 每天一道算法题(4)——O(1)时间内删除链表节点

    1.思路 假设链表......---A--B--C--D....,要删除B.一般的做法是遍历链表并记录前驱节点,修改指针,时间为O(n).删除节点的实质为更改后驱指针指向.这里,复制C的内容至B(此时 ...

  8. [tyvj1860]后缀数组

    题目链接:http://www.tyvj.cn/p/1860 解题关键:模板题.贴一个代码详解 http://www.cnblogs.com/staginner/archive/2012/02/02/ ...

  9. MQTT,XMPP,STOMP,AMQP,WAMP适用范围优缺点比较

    想要向服务器发送请求并获得响应?直接使用 HTTP 吧!非常简单.但是当需要通过持久的双向连接来通信时,如 WebSockets,当然你也有其它的选择. 这篇文章会简单扼要的解释 MQTT,XMPP, ...

  10. C++中的构造函数小结

    对象的初始化 对象时类的实例,类是不占用空间的,对象是占用空间的. 因为类是抽象的,不占用空间的,所以我们不能再定义类的时候对对象进行初始化操作的. 但是,我们可以定义一个函数,在类实例化一个对象的时 ...