B. Merge it!

You are given an array aanna1,a2,…,ana1,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][2,1,4][3,4][3,4][1,6][1,6][2,5][2,5]

Your task is to find the maximum possible number of elements divisible by 33

You have to answer tt

Input

The first line contains one integer tt1≤t≤10001≤t≤1000

The first line of each query contains one integer nn1≤n≤1001≤n≤100

The second line of each query contains nna1,a2,…,ana1,a2,…,an1≤ai≤1091≤ai≤109

Output

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

代码:

 #include<iostream>
#include<algorithm>
using namespace std;
int main() {
int n,m;
cin>>n;
for(int i=; i<n; i++) {
int cnt=,cnt1=,a1=,b1=;
int a[];
int b[];
cin>>m;
for(int j=; j<m; j++) {
cin>>a[j];
if(a[j]%==) {
cnt++;
} else {
a[j]%=;
b[cnt1++]=a[j];
}
}
for(int i=; i<cnt1; i++) {
if(b[i]==) {
a1++;
}
if(b[i]==) {
b1++;
}
}
if(a1>b1) {
int h=a1-b1;
if(h>=) {
cnt+=h/;
}
cnt+=b1;
} else {
int h=b1-a1;
if(h>=) {
cnt+=h/;
}
cnt+=a1;
}
cout<<cnt<<endl;
}
}

思路分析:若本身可整除3就加1,将不可整除3的数模3,都转化成1和2,比较1和2的数量,1比2多那就配对2数量个3,然后看1比2多了几个,如果超过3,看有多少个3,再记数。

链接:https://codeforces.com/contest/1176/problem/B

Codeforces1176B(B题)Merge it!的更多相关文章

  1. LeetCode算法题-Merge Sorted Array(Java实现)

    这是悦乐书的第161次更新,第163篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第20题(顺位题号是88).给定两个排序的整数数组nums1和nums2,将nums2中 ...

  2. [LC]88题 Merge Sorted Array (合并两个有序数组 )

    ①英文题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. N ...

  3. leetcode第22题--Merge k Sorted Lists

    problem:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its compl ...

  4. LeetCode算法题-Merge Two Binary Trees(Java实现)

    这是悦乐书的第274次更新,第290篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第142题(顺位题号是617).提供两个二叉树,将其合并为新的二叉树,也可以在其中一个二 ...

  5. 【算法】LeetCode算法题-Merge Two Sorted List

    这是悦乐书的第148次更新,第150篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第7题(顺位题号是21).合并两个已排序的链表并将其作为新链表返回. 新链表应该通过拼接 ...

  6. 第十二题 Merge Sorted Array

    Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...

  7. [LC]21题 Merge Two Sorted Lists (合并两个有序链表)(链表)

    ①英文题目 Merge two sorted linked lists and return it as a new list. The new list should be made by spli ...

  8. 链表经典题Merge Two Sorted Lists

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  9. LeetCode专题-Python实现之第21题:Merge Two Sorted Lists

    导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...

随机推荐

  1. 使用 GoLand 启动 运行 Go 项目

    来源:https://my.oschina.net/u/3744526/blog/3085468 在使用本博客经验之前 需配置好 GOPATH 跟 GOROOT 创建好本地工作路径之后,使用 GoLa ...

  2. linux下批量删除文件

    1. 在linux批量删除多级目录下同一格式的文件,可采用find + exec命令组合: 如在删除old目录下的,所有子目录中,后缀为.l的文件方法为: find old -type f -name ...

  3. 【JAVA基础】06 面向对象

    1. 面向对象思想概述 面向过程思想概述 第一步 第二步 面向对象思想概述 找对象(第一步,第二步) 举例 买煎饼果子 洗衣服 面向对象思想特点 是一种更符合我们思想习惯的思想 可以将复杂的事情简单化 ...

  4. Ubuntu下访问Windows中Postgresql

    因为项目的原因,需要将Ubuntu中的一些信息记录到Windows中的Postgresql数据库中,查看网上信息,最后成功了,特地记录以下,需要以下步骤: (1)在Windows中Postgresql ...

  5. centos分配IP脚本--写的第一个shell脚本

    IDC小菜鸟一枚,非科班出身.常常有客户的centos服务器需要分配15个IP甚至30个IP.每次需要手动分配十分麻烦,于是花了一天时间学了shell脚本,写了这个脚本. #!/bin/bash re ...

  6. Highcharts的自适应DOM或者DIV,JS方法实现

    那我们就按照官网的一分钟极速入门代码来说 // 图表配置 var options = { chart: { type: 'bar' //指定图表的类型,默认是折线图(line) }, title: { ...

  7. Mockjs+Ajax实践

    需要完成的工作:利用mock js随机生成数据,通过ajax请求,获取这些数据并展示在网页中. 一 mock js随机生成数据 官方文档中,Mock.mock( ),可以说是mock的精髓所在. Mo ...

  8. android 动画学习总结

    本文内容是本人阅读诸多前辈的学习心得后整理的,若有雷同,请见谅 Android 动画 分类:帧动画,补间动画,属性动画  . 1.帧动画 将一张张单独的图片连贯的进行播放,从而在视觉上产生一种动画的效 ...

  9. keras-深度学习处理文本数据

    深度学习用于自然语言处理是将模式识别应用于单词.句子和段落,这与计算机视觉是将模式识别应用于像素大致相同.深度学习模型不会接收原始文本作为输入,它只能处理数值张量,因此我们必须将文本向量化(vecto ...

  10. 涉及secureCRT中文显示的一些设置

    1.secureCRT中文显示乱码: 如果你的linux本身是显示着中文的,可进行如下设置: 选项->会话选项 外观->字符编码改为UTF-8,确定即可 2.secureCRT中文横向显示 ...