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. TP5 JSON对象数组转换为普通数组

    来源于:https://blog.csdn.net/lingchen__/article/details/67671047 使用TP5框架做项目时,对于数据的查询返回的都是对象,虽然也可以当做普通的数 ...

  2. java程序员从小工到专家成神之路(2020版)

    目录 必须掌握的基础知识 1. Git & Github 2. Linux 3. 数据结构和算法 4. HTTP / HTTPS 5. 设计模式 6. 计算机原理 java学习之路 1. 工具 ...

  3. 【linux三剑客】sed命令

    sed - stream editor for filtering and transforming text sed 流编辑器 strem edition,实现对文件的增删改替换查是Linux中第二 ...

  4. 配置路由器/交换机的Telnet登录

    实验目的:给配置路由器/交换机管理IP地址.设置Telnet的登录帐号.密码. 第一步:配置路由器的名称.接口IP地址. Switch> Switch>en Switch# Switch# ...

  5. Rancher流水线配置文档

    2019独角兽企业重金招聘Python工程师标准>>> 一.概述 Rancher流水线从逻辑上可以分为两部分,即CI和CD. CI,可分化为克隆代码.代码打包.发布镜像三部分. CD ...

  6. INTERVIEW #3

    菊厂的面试本来没打算记录,因为当时投的是非技术岗(技术支持).为了全面,就寥做记录. 菊厂的面试因为有口头保密协议,所以不能透露具体题目. 0 群面 简历通过筛选后,会有短信通知去面试. 非技术岗第一 ...

  7. unittest(封装用例)

    from selenium import webdriver from time import sleep import unittest #导入unittest库 import HTMLTestRu ...

  8. python3yupython2的差别

    1.长整型 # python2中才有长整型概念,python3中只有整形一说 # 定义方法:变量名=整数+l (小写L) #python2环境下 >>> a=123456789123 ...

  9. Linux常用的安全加固

    一.账号和口令 1.1 禁用或删除无用账号 减少系统无用账号,降低安全风险. 操作步骤userdel <用户名> //删除不必要的账号.passwd -l <用户名> //锁定 ...

  10. 低价购买(LIS方案统计)

    题意:https://www.luogu.com.cn/problem/P1108 如果两个数列组成的数字完全相同,那我们说这两个数列相同. 求出最长下降子序列的方案数. 题解来自 wjyyy大神. ...