Description
三倍游戏是一个单人游玩的益智游戏。玩家会随机得到 n 张卡片,每张卡片上写有数字,第 i 张卡片上的数字为 ai。每一轮游戏,玩家需要取走两张卡片,这两张卡片的数字之和需要为 3 的倍数,被选出的卡片不再放回原卡片堆中。
给定卡片数量 n 及每张卡片上的数字 a1,a2,⋯,an,请求这个游戏最多可以进行多少轮。
Input
第一行:单个正整数 n;1≤n≤100000。
第二行:n 个正整数 a1,a2,⋯,an。1≤ai≤1,000,000;
Output
单个自然数:表示答案。
Sample Input 1
4 1 3 3 2
Sample Output 1
2
Code
#include<stdio.h>
int main()
{
int num,t,a=0,b=0,c=0,sum=0;
scanf("%d",&num);
for(int i=0; i<num; i++)
{
scanf("%d",&t);
if(t%3==0)
a++;
else if(t%3==1)
b++;
else
c++;
sum=a/2;
if(b<c)
sum+=b;
else
sum+=c;
}
printf("%d",sum);
return 0;
}