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. flash导出正常清晰(无色差)GIF图片

    前言: 这枚GIF算是半临摹作品.我使用的FLASH制作这个小动画,其实这类型的动画用AE做会更便捷. 进入主题前,先摆出个成品 教程结束,以上就是flash制作出来的小动画怎么导出正常清晰(无色差) ...

  2. PHP中间uniqid在高并发重复问题

    在公用事业最近项目生成token检查问题.首先考虑php中间uniqid()函数生成一个随机字符串,但因为该函数的良好似基于微秒的水平.在高并发的情况下,,也能够产生相同的值. 解1:uniqid(r ...

  3. poj 1125 Stockbroker Grapevine(多源最短)

    id=1125">链接:poj 1125 题意:输入n个经纪人,以及他们之间传播谣言所需的时间, 问从哪个人開始传播使得全部人知道所需时间最少.这个最少时间是多少 分析:由于谣言传播是 ...

  4. JS-LINQ

    JS中使用LINQ 详细使用方法可找相关资料 文件在这里 引用: <script type="text/javascript" src="@Url.Content( ...

  5. linuxC动态内存泄漏追踪方法

    C里面没有垃圾回收机制,有时候你申请了动态内存却忘记释放,这就尴尬了(你的程序扮演了强盗角色,有借有还才是好孩子).当你想找出内存泄露的地方时,有的投入海量的代码中,头痛不已.还好GNU C库提供了些 ...

  6. MVC 直接或间接继承自ActionResult的类型

    •ViewResult:使用View()可以指定一个页面,也可以指定传递的模型对象,如果没有指定参数则表示返回与Action同名的页面 •ContentResult:使用Content(string ...

  7. 虚拟机安装的kali无法识别本机物联网卡

    http://blog.csdn.net/sb985/article/details/76427624

  8. 图像滤镜艺术---PS图像转手绘特效实现方案

    原文:图像滤镜艺术---PS图像转手绘特效实现方案 手绘效果实现方案 本文介绍一种PS手绘效果的实现方案,PS步骤来自网络,本文介绍代码实现过程. 整体看来,虽然效果还是有很大差异,但是已经有了这种特 ...

  9. ARTS 1.7 - 1.11

    每周一个 Algorithm,Review 一篇英文文章,总结一个工作中的技术 Tip,以及 Share 一个传递价值观的东西! Algorithm: 学习算法 题目: https://leetcod ...

  10. 微信小程序把玩(二)window配置

    原文:微信小程序把玩(二)window配置 window用于设置小程序的状态栏.导航条.标题.窗口背景色.注意在app.json中配置的属性会被子window属性覆盖 只需在app.json配置即可