Codeforces Round #565 (Div. 3) B
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #565 (Div. 3) A
A. Divide it! 题目链接:http://codeforces.com/contest/1176/problem/A 题目 You are given an integer n You ca ...
- Codeforces Round #565 (Div. 3) F.Destroy it!
题目地址:http://codeforces.com/contest/1176/problem/F 思路:其实就是一个01背包问题,只是添加了回合和每回合的01限制,和每当已用牌数到了10的倍数,那张 ...
- 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/ ...
- 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 ...
- Codeforces Round #565 (Div. 3) C. Lose it! (思维)
题意:给你一串只含\(4,8,15,16,23,42\)的序列,如果它满足长度是\(6\)的倍数并且有\(\frac {k}{6}\)个子序列是\([4,8,15,16,23,42]\),则定义它是好 ...
- 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 ...
随机推荐
- C#选择多个文件并读取多个文件数据
原文:C#选择多个文件并读取多个文件数据 版权声明:本文为博主原创文章,转载请附上链接地址. https://blog.csdn.net/ld15102891672/article/details/8 ...
- vcl控件经常使用属性和方法
TTabControl属性 DisplayRect:仅仅定该控件客户区的一个矩形 HotTrack:设置当鼠标经过页标签时,它的字是否有变化.假设为True,是字会变成蓝色Images:为每一个页标签 ...
- WPF 3D模型的一个扩展方法
原文:WPF 3D模型的一个扩展方法 在WPF 3D中,我们常常需要改变一个ModelVisual3D对象的颜色. 先说说ModelVisual3D,本质上3D模型都是由一个个的三角形构成的,并且经过 ...
- 微信小程序--实现图片上传
前端: 微信开发者工具 后端:.Net 服务器:阿里云 这里介绍微信小程序如何实现上传图片到自己的服务器上 前端代码 data: { productInfo: {} }, //添加Banner bin ...
- 不使用运算符(+、-、*、/) 来进行四则运算(C#)
最近在LeetCode 上刷题,遇到一个非常有趣的题目,题目的大概意思就是在不使用运算符的情况下实现两个数的加法...原题点这里>>> 说实话,刚看到这题目,我是一脸懵逼的. 后来仔 ...
- 运行时动态伪造vsprintf的va_list
运行时动态伪造vsprintf的va_list #include <stdio.h> int main() { char* m = (char*) malloc(sizeof(int)*2 ...
- WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化
原文:WPF在3D Cad模型中利用TextureCoordinates实现颜色渐变显示偏差值的变化 注:最近在做3D机械模型重建方面的软件,需要根据光栅传感器采集的数据绘制3D图形,并显示出色差以及 ...
- WPF Timeline简易时间轴控件的实现
原文:WPF Timeline简易时间轴控件的实现 效果图: 由于整个控件是实现之后才写的教程,因此这里记录的代码是最终实现后的,前后会引用到其他的一些依赖属性或者代码,需要阅读整篇文章. 1.确定T ...
- Adapter的泛型
宗旨:GetView方法放在具体的Activity/Fragment里面实现,其他的均可以复用 /// <summary> /// 通用适配器:新建GetViewEvent委托+OnGet ...
- XF 显示网络图像
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...