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 ...
随机推荐
- Spring综合Struts2
1.1. Spring综合Struts2 1) 该Spring用户手机WEB-INF下一个 2) 把Spring配置文件配置到web.xml中 <!-- 引入Spr ...
- 【从翻译mos文章】在oracle db 11gR2版本号被启用 Oracle NUMA 支持
在oracle db 11gR2版本号被启用 Oracle NUMA 支持 参考原始: Enable Oracle NUMA support with Oracle Server Version 11 ...
- Lizcst Software Lab新秀品牌上线!
科友微电机是Lizcst Software Lab旗下品牌新秀,专业经营各种微型特种直流电机.微型发电机.微型电机配件.航模车模船模素材.教学科学小制作材料的网店.本店秉承Lizcst Softwar ...
- Command 传参的几种方式
Command可以根据CommandParameter传参 关键代码 public ICommand SubmitCommand => _submitCommand; private Relay ...
- Angular常用指令
安装Node 先去Node官网下载并安装Node.js Install the Angular CLI(安装Angular CLI) npm install -g @angular/cli Creat ...
- WPF实现选项卡效果(2)——动态添加AvalonDock选项卡
原文:WPF实现选项卡效果(2)--动态添加AvalonDock选项卡 简介 在前面一篇文章里面,我们使用AvalonDock实现了类似于VS的选项卡(或者浏览器的选项卡)效果.但是我们是通过xaml ...
- 最简单的IdentityServer实现——Api
1.创建项目并添加引用 创建ASP.NET Core Web API项目IdentityServer.EasyDemo.Api 1 2 引用IdentityServer4.AccessToke ...
- 【全面解禁!真正的Expression Blend实战开发技巧】第一章 真正的开发中的最佳的做法
原文:[全面解禁!真正的Expression Blend实战开发技巧]第一章 真正的开发中的最佳的做法 从设计者到开发者 设计师创建一个应用程序的布局然后让开发者去实现. 从开发者到设计者 开发者创建 ...
- ELINK离线编程器常见问题
Q1 编程器是否可以接JTAG JTAG接口已经包含SWD接口引脚,按以下引脚对应接线即可: SWDIO->目标板JTAG 的JTMS SWCLK->目标板JTAG 的JTCK Q2 PC ...
- MySQL学习-SQL约束
约束分类 主键:PRIMARY KEY用于唯一标识表中的一行,不可重复.e.g.:id INT(10) PRIMARY KEY 默认值:DEFAULT插入时,若没有指定该列的值,则为DEFAULT指定 ...