Codeforces1176B(B题)Merge it!
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
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
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,再记数。
Codeforces1176B(B题)Merge it!的更多相关文章
- LeetCode算法题-Merge Sorted Array(Java实现)
这是悦乐书的第161次更新,第163篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第20题(顺位题号是88).给定两个排序的整数数组nums1和nums2,将nums2中 ...
- [LC]88题 Merge Sorted Array (合并两个有序数组 )
①英文题目 Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. N ...
- leetcode第22题--Merge k Sorted Lists
problem:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its compl ...
- LeetCode算法题-Merge Two Binary Trees(Java实现)
这是悦乐书的第274次更新,第290篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第142题(顺位题号是617).提供两个二叉树,将其合并为新的二叉树,也可以在其中一个二 ...
- 【算法】LeetCode算法题-Merge Two Sorted List
这是悦乐书的第148次更新,第150篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第7题(顺位题号是21).合并两个已排序的链表并将其作为新链表返回. 新链表应该通过拼接 ...
- 第十二题 Merge Sorted Array
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...
- [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 ...
- 链表经典题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 ...
- LeetCode专题-Python实现之第21题:Merge Two Sorted Lists
导航页-LeetCode专题-Python实现 相关代码已经上传到github:https://github.com/exploitht/leetcode-python 文中代码为了不动官网提供的初始 ...
随机推荐
- 地点下来框的实现(php)
效果图: 样式(bootstrap): class="selectpicker show-tick form-control",就是多了个form-contro就行了 概念: 这里 ...
- 2019-2020-1 20199326《Linux内核原理与分析》第三周作业
第三周学习内容 庖丁解牛Linux内核分析第二章:操作系统是如何工作的 Linux内核分析实验二 学到的一些知识 计算机的三大法宝:存储程序计算机,函数调用堆栈,中断 堆栈是C语言程序运行时必须使用的 ...
- Shiro(三):Spring-boot如何集成Shiro(下)
上一篇文章介绍了shiro在spring-boot中通过filter实现authentication流程(通过设置filterMaps也可以达到authorization的目的):这篇文章主要介绍sp ...
- RHCS图形界面建立GFS共享下
我们上面通过图形界面实现了GFS,我们这里使用字符界面实现 1.1. 系统基础配置 5台节点均采用相同配置. 配置/etc/hosts文件 # vi /etc/hosts 127.0.0. ...
- python(json 模块)
1.Json 定义 定义:JSON(JavaScript Object Notation, JS 对象简谱) 是一种轻量级的数据交换格式.JSON 的数据格式其实就是 python 里面的字典格式,里 ...
- Nginx模块开发(5)————开发简单的HTTP过滤模块
该模块可实现如下的功能,在浏览器输入http://你的IP/lcw.text,能够读出你在根目录下创建的lcw.txt里面的内容,并在前面加上一句字符串where there is a will,th ...
- Find Minimum in Rotated Sorted Array(旋转数组的最小数字)
题目描述: Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., might become ...
- B. Heaters 思维题 贪心 区间覆盖
B. Heaters 这个题目虽然只有1500的分数,但是我还是感觉挺思维的,我今天没有写出来,然后看了一下题解 很少做这种区间覆盖的题目,也不是很擅长,接下来讲讲我看完题解后的思路. 题目大意是:给 ...
- xpath加PHP对网站相关数据的截取
首先了解一串代码 <?php $url = 'http://www.baidu.com';$ch = curl_init();curl_setopt($ch, CURLOPT_FILE, fo ...
- qgis控制滚轮转动地图比例尺的变化幅度
需求:在比例尺1万-10万之间,鼠标滚轮转动比例尺的变化幅度为1万重写滚轮事件 void Xx::wheelEvent(QWheelEvent*event){ double curScale = sc ...