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 ...
随机推荐
- ACM学习历程—Hihocoder 1233 Boxes(bfs)(2015北京网赛)
hihoCoder挑战赛12 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 There is a strange storehouse in PKU. In this ...
- JS性能之滚动条之外的其他部分
问题: 如果一个页面宽高比较大,也就是页面需要滚动条来查看其他页面内容,这时候,在滚动条之外的其他部分,是依然处于运行状态. 比如那部分有视频播放,则那些视频虽然在当前窗口看不到,但它们还是会处于播放 ...
- C#中如何获取汉字的笔画数和汉字的拼音
以前玩过一个游戏,输入两个人的名字然后点击缘分就能产生一段缘分测试的结果,后来经过分析知道是根据名字笔画数之差来弄的小游戏,于是就在百度上找怎么得到汉字的笔画数,也没找到自己想要的答案,问遍了所有的人 ...
- yum软件包管理器
Yum (Yellow dog Updater, Modified) 黄狗升级器是一个在 Fedora 中的字符前端软件包管理器.基于 RPM 包管理(介绍见RPM包及其管理),能够从指定的服务器自动 ...
- PowerDesigner生成CDM模型
一.新建概念数据模型 1)选择File-->New,弹出如图所示对话框,选择CDM模型(即概念数据模型)建立模型. 2)完成概念数据模型的创建.以下图示,对当前的工作空间进行简单介绍.(以后再 ...
- Project Server调用PSI关闭任务以进行更新锁定任务
/// <summary> /// 锁定和解锁项目任务 /// </summary> /// <param name="projectuid"> ...
- Java探索之旅(7)——对象的思考
1.知识要点 ❶不可变类:一旦创建,其内容不能改变的类称之为不可变类.满足:⑴所有数据域私有,⑵没有修改器,⑶没有访问器方法,其返回一个指向可变数据域的引用.(这样通过引用就能修改私有数据域).比如, ...
- AngularJs(Part 6)
Overcomming same-origin policy restrictions with JSONP. AJAX has a restriction that it can only retr ...
- 树莓派 Learning 002 装机后的必要操作 --- 05 给树莓派搭建“x86 + pi”环境 -- 安装**32位运行库** -- 解决`E:未发现软件包 xxx` 问题
树莓派 装机后的必要操作 - 给树莓派搭建"x86 + pi"环境 – 安装32位运行库 – 解决E:未发现软件包 xxx 问题 我的树莓派型号:Raspberry Pi 2 Mo ...
- OpenGL 使用GLFW创建全屏窗口
OpenGL 使用GLFW创建全屏窗口 GLFW库里面的glfwCreateWindow()函数是用来创建窗口的函数. 这样函数的原型是: GLFWwindow* glfwCreateWindow(i ...