链接:

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;
}

转载于:https://www.cnblogs.com/YDDDD/p/10998706.html

Codeforces Round #565 (Div. 3) B. Merge it!相关推荐

  1. Codeforces Round #565 (Div. 3) A B C E

    Codeforces Round #565 (Div. 3) A Divide it! 由题可知,分别消掉1个2,3,5分别需要1,2,3的花费 #include<bits/stdc++.h&g ...

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

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

  3. 【Codeforces Round #565 (Div. 3) A B C D E F】解题报告

    Codeforces 565 失踪人口回归 cf 565 A 题意 你可以把一个偶数变成 n/2 , 可以把一个3的倍数变成 n2/3, 可以把一个5的倍数变成 n4/5 问你最少通过多少步可以变成1 ...

  4. 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 ...

  5. Codeforces Round #740 (Div. 2) F. Top-Notch Insertions 线段树 / 平衡树 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 思路: 考虑最终的序列是什么鸭子的,首先序列肯定单调不降,也就是a1≤a2≤a3≤...≤ana_1\le a_2\le a_3\le ...\le a_na ...

  6. Codeforces Round #727 (Div. 2) E. Game with Cards dp + 思维

    传送门 文章目录 题意: 思路: 题意: 初始有左右手,上面各有一个数字为000的卡牌,每次都有一个新卡kik_iki​,你可以将其放在左手或者右手,使两只手上的卡片范围在[ll,i,rl,i][l_ ...

  7. Codeforces Round #626 (Div. 2) D. Present 按位贡献 + 快排新姿势

    传送门 文章目录 题意: 思路: 题意: 给你一个长度为nnn的序列aaa,让你计算 n≤4e5,a≤1e7n\le 4e5,a\le 1e7n≤4e5,a≤1e7 思路: 首先这个式子是n2n^2n ...

  8. Codeforces Round #556 (Div. 1)

    Codeforces Round #556 (Div. 1) A. Prefix Sum Primes 给你一堆1,2,你可以任意排序,要求你输出的数列的前缀和中质数个数最大. 发现只有\(2\)是偶 ...

  9. Codeforces Round #747 (Div. 2)题解

    Codeforces Round #747 (Div. 2)题解 (本博客将持续更新以后每场CF div2的题解,喜欢ACM.OI的小伙伴记得点个关注哟) 昨天夜晚刷网络流刷入迷了,渐渐就忘记了我还要 ...

最新文章

  1. 如何识别和避免间谍软件
  2. 2019年人工智能硬件与应用大趋势
  3. linux 实验 广技师 进程管理与系统监视,Linux系统管理之进程管理
  4. typedef 多文件引用
  5. python数据对比找不同,不同模式间的数据比较技术
  6. POJ 2096 Collecting Bugs:期望dp
  7. JAVA,如何判断点是否在面内
  8. C++11 并发指南三(Lock 详解)(转载)
  9. linux的set命令详解,Linux_批处理 Set 命令详解 让你理解set命令,set,E文翻译过来就是“设置” - phpStudy...
  10. 别动我的代码!聊聊那些代码保护的艺术
  11. c语言课后答案详解,c语言课后练习题答案详解_0.doc
  12. python花瓣飘零_PYTHON抓取花瓣网高清美图
  13. 一款 Java 开源的 Spring Boot 即时通讯 IM 聊天系统(源码自取)
  14. 外卖小程序对接飞鹅小票打印的实现
  15. C语言实现的个人信息管理系统
  16. 硬件/操作系统/网络(九):了解常见linux服务器硬件配置
  17. 关于手机使用中信号强弱 网速快慢 频段的相关常识
  18. 微信小程序实现当前页面多个视频文件只能播放一个视频,其他视频暂停,点击当前暂停当前
  19. 个人理财--知识点总结
  20. Mysql 不使用窗口函数实现分组排序 rank 别名问题

热门文章

  1. crontab定时任务常见问题
  2. 交换机网络故障及原因分析集锦
  3. 【Oracle】DG中物理备库、快照备库的相互转换
  4. ServerVersion 引发了“System.InvalidOperationException”类型的异常
  5. Sharepoint 2010 解决DFWP - Unable to display this Web Part 的问题
  6. 记因循环依赖的解决方案
  7. MyBatis学习(01)之解决mapper绑定异常
  8. SQL Server抛出异常信息 RAISERROR
  9. java下载文件名乱码的解决方法
  10. nginx实现动态分离,解决css和js等图片加载问题