B. Merge it!

题目链接:http://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.
Input
The first line contains one integer t (1≤t≤1000) — the number of queries.

The first line of each query contains one integer n
(1≤n≤100).

The second line of each query contains n
integers a1,a2,…,an (1≤ai≤109).
Output

For each query print one integer in a single line — the maximum possible number of elements divisible by 3

that are in the array after performing described operation an arbitrary (possibly, zero) number of times.
Example

Input
2
5
3 1 2 3 1
7
1 1 1 1 1 2 2

Output
3
3

Note

In the first query of the example you can apply the following sequence of operations to obtain 3
elements divisible by 3: [3,1,2,3,1]→[3,3,3,1]

In the second query you can obtain 3
elements divisible by 3 with the following sequence of operations: [1,1,1,1,1,2,2]→[1,1,1,1,2,3]→[1,1,1,3,3]→[2,1,3,3]→[3,3,3].

题意

给你一个数组,可以相加任意两个数,让你输出相加任意次数后该数组里的数是3的倍数的个数

思路

3=1+2,所以记录该数组里%3为1的个数了,和%3为2的个数了,之后就可以算结果了,别忘了还存在三个%3为1或2的相加也是3的倍数。

//
// Created by hjy on 19-6-5.
//
#include<bits/stdc++.h> using namespace std;
const int maxn = 2e5 + ;
int main()
{ int T;
cin>>T;
while(T--)
{
int t;
cin>>t;
int x;
vector<int>sh,ch;
int sum=;
for(int i=;i<t;i++)
{
cin>>x;
if(x%==)
sum++;
else
sh.push_back(x%);
}
int _1=,_2=; for(int i=;i<sh.size();i++)
{
if(sh[i]==)_1++;
else _2++;
}
cout<<sum+min(_1,_2)+(max(_1,_2)-min(_1,_2))/<<endl;
}
return ;
}

最新文章

  1. 创建ASP.NET Core MVC应用程序(1)-添加Controller和View
  2. js 闭包 理解
  3. POJ2230Watchcow[欧拉回路]
  4. SharePoint 2013 新功能探索 之 列表等级设置
  5. win10自动更新彻底关闭
  6. CentOS查看CPU、内存、网络流量和磁盘 I/O【转载,待整理】
  7. iPhone —— 如何自制铃声(图文)
  8. Qt读写二进制文件
  9. usaco /the second wave
  10. Android开发之自定义Spinner样式的效果实现(源代码实现)
  11. vs提示“当前不会命中断点,源代码与原始版本不同”的一种解决办法
  12. CCNP交换实验(7) -- NAT
  13. windows下一个erlang包装镜像启动
  14. JSONP 的工作原理是什么?
  15. Oracle BEQ方式连接配置
  16. Java和C++的对比
  17. phpstorm 2017.2激活
  18. Invalid bound statement (not found)解决方法
  19. LeetCode &amp; Q14-Longest Common Prefix-Easy
  20. Dynamics CRM Odata QueryUrl中的SetName问题

热门文章

  1. 使用xtrabackup实现MySQL主从复制
  2. WinEdt && LaTex(四)—— 自定义新命令(newcommand、def)
  3. C++安全异常std:auto_ptr
  4. UVA10940 - Throwing cards away II(找到规律)
  5. asp .net core 使用spa
  6. WPF查找父元素子元素
  7. AY写给国人的教程- VS2017 Live Unit Testing[1/2]-C#人爱学不学-aaronyang技术分享
  8. 在WPF中实现图片一边下载一边显示
  9. 自动启动 Windows 10 UWP 应用
  10. Win8Metro(C#)数字图像处理--2.27图像加法运算