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

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

  1. Codeforces Round #565 (Div. 3) B. Merge it!

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

  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 #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

随机推荐

  1. WPF-WPF BitmapEffect (按钮凹凸效果)

    原文:WPF-WPF BitmapEffect (按钮凹凸效果) BitmapEffect位图效果是简单的像素处理操作.它可以呈现下面几种特殊效果.              BevelBitmapE ...

  2. 使用python3的base64编解码实现字符串的简易加密解密

    import base64 copyright = 'Copyright (c) 2012 Doucube Inc. All rights reserved.' def main(): #转成byte ...

  3. crossplatform---Nodejs in Visual Studio Code 03.学习Express

    1.开始 下载源码:https://github.com/sayar/NodeMVA Express组件:npm install express -g(全局安装) 2.ExpressRest 打开目录 ...

  4. C#: Get current keyboard layout\input language

    原文 https://yal.cc/csharp-get-current-keyboard-layout/ On some occasions, you may want to get a " ...

  5. AABB边框、OBB边框、通过比较球包围

    1) AABB 包围盒: AABB 包围盒是与坐标轴对齐的包围盒, 简单性好, 紧密性较差(尤其对斜对角方向放置的瘦长形对象, 採用AABB, 将留下非常大的边角空隙, 导致大量不是必需的包围盒相交測 ...

  6. zend-form笔记

    Zend-Form组件包含以下几个对象: 1.Elements:包含了name和attributes, 2.Fieldsets:继承自elements,但允许包含其他fieldset和elements ...

  7. 如何将JPEG缩略图放到LISTVIEW中(delphi listview自绘图形)

    http://www.docin.com/p-567657457.html?qq-pf-to=pcqq.c2c http://www.cnblogs.com/snow001x/archive/2008 ...

  8. Win10《芒果TV》更新v3.8.30流星版:优化稳定性、升级无边框播放体验

    随着暑假到来,大波王牌综艺和青春电视剧热浪来袭,Win10版<芒果TV>全平台同步更新流星版v3.8.30,进一步提升稳定性,巩固播放体验,升级剧场模式和画中画无边框体验,我们在芒果等你. ...

  9. ArcGIS for Desktop入门教程_第二章_Desktop简介 - ArcGIS知乎-新一代ArcGIS问答社区

    原文:ArcGIS for Desktop入门教程_第二章_Desktop简介 - ArcGIS知乎-新一代ArcGIS问答社区 1 Desktop简介 1.1 ArcGIS for Desktop ...

  10. eclipse 插件编写(四)

    前言 前面几篇文章讲了下如果编写简单的eclipse插件,如创建插件项目.编写右键弹出菜单等功能,接下来主要写一下如何生成代码的功能,这一片的功能跟插件本身的编写关联不太大,主要处理插件之后的业务内容 ...