码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces 1176B - Merge it!

时间:2019-06-14 00:45:13      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:namespace   int   col   mamicode   题目   out   std   http   +=   

题目链接:http://codeforces.com/problemset/problem/1176/B

技术图片


题意:给定序列,任意俩个元素可以相加成一个元素,求序列元素能被3整除的最大数量。

思路: 对于所有元素进行 模3 的预处理,然后 看代码吧

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int t;
 6     int a[105];
 7     cin >> t;
 8     while(t--)
 9     {
10         int n;
11         cin >> n;
12         int ans = 0;
13         int a1 = 0,a2 = 0;
14         for(int i = 0;i < n;i++)
15         {
16             cin >> a[i];
17             a[i] %= 3;
18             if(a[i] == 0) ans++;
19             else if(a[i] == 1) a1++;
20             else if(a[i] == 2) a2++;
21         }
22         if(a1 == a2) cout << ans + a1 << endl;
23         else
24         {
25             int m = min(a1,a2);
26             ans += m +(a1+a2-2*m)/3;
27             cout << ans << endl;
28         }
29     }
30     return 0;
31 }

 

Codeforces 1176B - Merge it!

标签:namespace   int   col   mamicode   题目   out   std   http   +=   

原文地址:https://www.cnblogs.com/Carered/p/11020417.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!