Codeforces Round #565 (Div. 3) B. Merge it!
链接:
https://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.
思路:
找除三的余数,优先配对1和2.
再3个1或3个2可以配成一个。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e2 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
int a[3];
int main()
{
scanf("%d", &t);
while (t--)
{
memset(a, 0, sizeof(a));
scanf("%d", &n);
int v;
for (int i = 1;i <= n;i++)
{
scanf("%d", &v);
a[v%3]++;
}
if (a[1] > a[2])
swap(a[1], a[2]);
int res = a[0]+a[1]+(a[2]-a[1])/3;
cout << res << endl;
}
return 0;
}
Codeforces Round #565 (Div. 3) B. Merge it!的更多相关文章
- Codeforces Round #565 (Div. 3) B
B. Merge it! 题目链接:http://codeforces.com/contest/1176/problem/B 题目 You are given an array a consistin ...
- 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 #446 (Div. 2)
Codeforces Round #446 (Div. 2) 总体:rating涨了好多,虽然有部分是靠和一些大佬(例如redbag和ShichengXiao)交流的--希望下次能自己做出来2333 ...
随机推荐
- 在Debug中使用断点调试程序
我最近在学习汇编的程序,所以很多都需要动手写点代码去测试,如果是测试三五行代码的还比较简单,可以在debug中直接按T进行单步调试,但是到后来调试的代码越来越复杂,越来越长,如果再使用单步调试不知道要 ...
- bzoj 4815 小Q的表格 —— 反演+分块
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4815 思路就和这里一样:https://blog.csdn.net/leolyun/arti ...
- Ubuntu下安装软件
在ubuntu当中,安装应用程序有三种方法,分别是:apt-get,dpkg安装deb和make install安装源码包三种. apt-get方法 使用apt-get install来安装应用程序算 ...
- Boost库之asio io_service以及run、run_one、poll、poll_one区别
一.io_service的作用 io_servie 实现了一个任务队列,这里的任务就是void(void)的函数.Io_servie最常用的两个接口是post和run,post向任务队列中投递任务,r ...
- Centos7搭建pptp
废话不多说,先上脚本地址:Centos7一键pptp 使用方法: wget https://raw.githubusercontent.com/DanylZhang/VPS/master/CentOS ...
- 转载:Android应用的自动更新模块
软件的自动更新一般都与Splash界面绑定在一起, 由于需要维护的软件界面很复杂, 一个Activity中嵌入ViewPager, 并且逻辑比较复杂, 索性重新写一个Activity, 现在的软件都很 ...
- LaTeX技巧203:如何实现等号对齐_LaTeX_Fun_新浪博客
LaTeX技巧203:如何实现等号对齐_LaTeX_Fun_新浪博客 我们在进行公式的输入排版的时候,通常希望公式比较齐整,所以需要一些等号对齐,或者左对齐,关于公式的左对齐前文已经介绍了方法.htt ...
- 安装 ambaria
hadoop安装 wget http://public-repo-1.hortonworks.com/ambari/centos6/1.x/updates/1.2.4.9/ambari.repo cp ...
- pig入门教程(2)
本文可以让刚接触pig的人对一些基础概念有个初步的了解. 本文的大量实例都是作者Darran Zhang(website: codelast.com)在工作.学习中总结的经验或解决的问题,并且添加了较 ...
- 在VM12中安装ubuntu系统下的VMTOOLS
转载自http://www.jb51.net/article/97387.htm 一.下载Ubuntu镜像: Ubuntu官网下载地址 二.创建虚拟机 打开VMware Workstation,点击创 ...